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

Question

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.

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.