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

Question

You are given n boolean variables (numbered 1..n) and a list of OR-clauses, each with exactly two literals. A literal is encoded as a positive integer v for variable v being true, or -v for variable v being false (e.g. the clause [1,-2] means (x1 OR NOT x2)). Return True if there exists an assignment of the variables that satisfies every clause, else False. Assume 1 <= n <= 2000 and up to a few thousand clauses; a literal may repeat a variable (e.g. [1,1] forces x1 true).

Implement
two_sat_satisfiable(n: int, clauses: list[list[int]]) → bool
Examples
in[2,[[1,2],[-1,2],[-2,1]]]outtrue
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.