Satisfiability of Equality Equations
Master this topic with zero to advance depth.
Satisfiability of Equality Equations
Given equations like 'a==b' or 'b!=a', check if it's possible to satisfy all equations.
Examples
Input: ["a==b","b!=a"]
Output: false
Approach 1
Level III: Union-Find (Double Pass)
Intuition
Pass 1: Process all '==' and union symbols into components. Pass 2: Process all '!=' and check if the symbols already share a root. If they do, it's a contradiction.
⏱ O(N \cdot \alpha(26))💾 O(26)
Detailed Dry Run
a==b (Union a,b). b==c (Union b,c). a!=c (Find a=c, Find c=c. Conflict!).
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.