 All Problems
Satisfiability of Equality Equations
medium
union-find
graph
string
google
amazon

You are given an array of strings equations where each string is of length 4 and represents a relation: either "a==b" or "a!=b".

Return true if all equations can be satisfied simultaneously, false otherwise.

Example 1:

Input: equations = ["a==b","b!=c","c==a"]
Output: false

Example 2:

Input: equations = ["c==c","b==d","x!=z"]
Output: true

Constraints:

  • 1 <= equations.length <= 500
  • equations[i].length == 4
  • equations[i][0] and equations[i][3] are lowercase letters
Run to check your code against the sample cases, or submit to run every case