Given a list of equality and inequality equations over lowercase letters, determine whether all equations can be satisfied simultaneously. DSU union by rank is a clean way to merge equal variables before checking conflicts.
equations = array of equality / inequality strings
whether all equations are satisfiable
Example 1:
Input:
equations = ["a==b","b!=c","c==a"]
Output:
false
Explanation:
After merging a, b, and c through equalities, the inequality b!=c cannot hold.
Example 2:
Input:
equations = ["a==b","b==c","a==c"]
Output:
true
Explanation:
All equalities are compatible.
Example 3:
Input:
equations = ["c==c","b==d","x!=z"]
Output:
true
Explanation:
Trivial equalities and unrelated inequalities are satisfiable.