1050. Satisfiability of Equality Equations

MediumGraphsDSUGraph

Given equations of the form "a==b" or "a!=b" over single lowercase-letter variables, determine whether it is possible to assign values so that all equations hold. Return true or false. The input is JSON {equations}.

Input: JSON {equations}.

Output: Boolean — true or false.

Examples

Example 1
Input: {"equations":["a==b","b!=a"]}
Output: false
Explanation: Contradiction.
Example 2
Input: {"equations":["a==b","b==c","a==c"]}
Output: true
Explanation: Consistent equalities.
Example 3
Input: {"equations":["a!=a"]}
Output: false
Explanation: A variable cannot differ from itself.

Constraints

Asked by

GoogleAmazonMeta
Solve this problem in the editor →