Boolean satisfiability
Your task
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.
Examples
solve_2sat(n: int, clauses: list[list[int]]) -> list[bool]Example 1
Input
solve_2sat(2, [[1, 2], [-1, 2], [-2, 1]])Output
[True, True]