Groups of Special-Equivalent Strings LeetCode solution in JavaScript

1
var numSpecialEquivGroups = function (words) {
2
const set = new Set();
3
const a = "a".charCodeAt(0);
4
const alphaCounter = new Array(26).fill(0);
5
for (const word of words) {
6
const [even, odd] = [[...alphaCounter], [...alphaCounter]];
7
word.split("").forEach((l, i) => {
8
l = l.charCodeAt(0) - a;
9
if (i % 2) odd[l]++;
10
else even[l]++;
11
});
12
const hashkey = even.join("") + odd.join("");
13
set.add(hashkey);
14
}
15
return set.size;
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0