1
var equationsPossible = function (equations) {
2
const A = "a".charCodeAt(0);
3
const n = equations.length;
4
const parent = new Array(26).fill(0).map((_, i) => i++);
5

6
const find = (x) => {
7
if (parent[x] === x) {
8
return x;
9
} else {
10
return (parent[x] = find(parent[x]));
11
}
12
};
13

14
for (const eq of equations) {
15
if (eq.charAt(1) === "=") {
16
parent[find(eq.charCodeAt(0) - A)] = find(eq.charCodeAt(3) - A);
17
}
18
}
19

20
for (const eq of equations) {
21
if (
22
eq.charAt(1) === "!" &&
23
find(eq.charCodeAt(0) - A) === find(eq.charCodeAt(3) - A)
24
) {
25
return false;
26
}
27
}
28

29
return true;
30
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0