The Satisfiability of Equality Equations interview question gives you a list of equations where each equation is either "x==y" or "x!=y" for single-character variable names. Determine whether all equations can be simultaneously satisfied. This is a graph connectivity problem solvable with Union-Find.
This problem is asked at Microsoft, Meta, UiPath, and Google because it demonstrates a non-obvious application of Union-Find (Disjoint Set Union): use equality equations to build connected components, then verify that no inequality equation contradicts the established components. It models constraint satisfaction — directly applicable to type inference in compilers, logical consistency checking, and database constraint validation.
The pattern is two-pass Union-Find. Pass 1: process all "==" equations and union the two variables (treat each letter as a node 0–25). Pass 2: process all "!=" equations and check that the two variables are NOT in the same component. If any "!=" equation has both variables in the same component (they are forced equal by "==" equations), return false. Otherwise, return true.
Equations: ["a==b", "b!=c", "c==a"]
Pass 1 (unions): a==b → union(a,b). c==a → union(c,a). Now {a,b,c} are in one component.
Pass 2 (check !=): b!=c → find(b) == find(c)? Yes (same component) → contradiction → return false.
Equations: ["a==b", "b!=c"]
true.!= equations in the first pass — they cannot be used to establish unions.== equations before checking ANY != — the order matters: build unions first, check inequalities second.find() function must be correct.For the Satisfiability of Equality Equations coding problem, the Union-Find graph interview pattern is the right tool. Two-pass processing — union all equalities first, then validate all inequalities — is the clean strategy. Google interviewers may ask "why not process them together?" — the answer is that equalities must propagate transitively through all nodes before inequalities can be checked. Practice implementing DSU with path compression for O(α(n)) amortized performance.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Cost to Convert String I | Medium | Solve | |
| Min Cost to Connect All Points | Medium | Solve | |
| Evaluate Division | Medium | Solve | |
| Minimum Cost Walk in Weighted Graph | Hard | Solve | |
| Check for Contradictions in Equations | Hard | Solve |