Graph Theory37 sections · 1633 units
Open in Course

LeetCode 990 Satisfiability of Equality Equations - Strategy

Two Passes

You treat each variable ('a', 'b'.) as a node.

1.1. First Pass (Process ==): If the equation is x == y, it means they belong to the same group. Perform dsu.unite(x, y).

2.2. Second Pass (Process!=): If the equation is x!= y, it means they must be in different groups.

Check dsu.find(x) == dsu.find(y). If they have the same leader, it is a contradiction! Return false.

3.3. If you finish both passes without conflict, return true.