Code Room2-SAT satisfiability
HardPrep Room Coding #1255

2-SAT satisfiability

CodingAlgorithms & data structuresSenior–Staff~40 min

You are wiring up a feature-flag system. There are n boolean variables (numbered 1..n) and a list of 2-clauses; each clause is a pair [a, b] of literals meaning (a OR b) must hold, where a positive integer i means variable i is true and -i means variable i is false. Determine whether some assignment of all n variables satisfies every clause. Constraints: 1 <= n <= 5000, clauses may be empty, and a literal pair may repeat or be a tautology like [i, -i].

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

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