Imagine you're a mathematician trying to solve a system of equations involving variables. You're given a collection of equality and inequality constraints between single-letter variables, and you need to determine if there's a way to assign integer values to these variables that satisfies all the given constraints simultaneously.
You are provided with an array of strings equations where each equation is exactly 4 characters long and follows one of two formats:
"xi==yi"- Variable xi must equal variable yi"xi!=yi"- Variable xi must NOT equal variable yi
Here, xi and yi are lowercase letters representing variable names (they can be the same letter).
Your task: Return true if it's possible to assign integer values to all variables such that every equation is satisfied, or false if such an assignment is impossible.
For example, if you have ["a==b", "b==c", "a!=c"], this is impossible because if a equals b and b equals c, then a must equal c, which contradicts the third equation.
Input & Output
Constraints
- 1 โค equations.length โค 500
- equations[i].length == 4
- equations[i][0] is a lowercase letter
- equations[i][1] is either '=' or '!'
- equations[i][2] is '='
- equations[i][3] is a lowercase letter