Code RoomBoolean satisfiability
HardPrep Room Coding #1446

Boolean satisfiability

CodingAlgorithms & data structuresSenior–Staff~40 min

You are given n boolean variables numbered 1..n and a list of clauses, each a 2-element list [a, b] representing the disjunction (a OR b). A literal is encoded as the variable's number, negated by a minus sign: 3 means variable 3 is True, -3 means variable 3 is False. Find any assignment of the variables that satisfies every clause. Return a list of n booleans (index 0 is variable 1, etc.). If no satisfying assignment exists, return an empty list. Constraints: 1 <= n <= 60; clauses may repeat and may reference a variable in both polarities.

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

0:00 of about 40 min
InputExpectedGot
[2,[[1,2],[-1,2],[-2,1]]][true,true]not run yetsample