Code Room
CodingHardcod-g706
Subject 2 satLevel Senior–Staff~45 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Given a 2-SAT instance over n boolean variables (1..n) and a list of clauses (each [a, b] meaning (a OR b), with positive i = variable i true and -i = false), first decide satisfiability. If UNSATISFIABLE, return -1. Otherwise return the count of FORCED variables: variables that take the SAME value in every satisfying assignment. Constraints: 1 <= n <= 2000; clauses may be empty, repeated, or tautological.

Implement
count_forced_variables(n: int, clauses: list[list[int]]) → int
Examples
in[3,[[1,2],[-1,2],[2,3],[-3,1]]]out1
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.