Satisfiability of Equality Equations
You are given equations of the form "a==b" or "a!=b", where each side is a single lowercase letter variable. Return true if it is possible to assign integer values to the variables so that all equations hold, and false otherwise.
Open official problem prompt ↗Decide whether a set of equality and inequality constraints over letter variables is jointly satisfiable.
Group people who must sit together (==), then check no 'must sit apart' rule (!=) applies to two people already forced into the same group.
- Input
- equations = ["a==b","b!=a"]
- Output
- false
- Why
- a==b forces a and b to be equal, but b!=a demands they differ, which is impossible.
1 <= equations.length <= 500equations[i].length == 4equations[i][0] and equations[i][3] are lowercase lettersequations[i][1] is '=' or '!'equations[i][2] is '='