1
var findTheLongestSubstring = function (s) {3
// 0 0 0 0 0 => initial state, all are even letters5
// 0 0 0 0 1 => at index 0, only a is odd count6
// 0 0 0 0 1 => at index 1, max = 17
// 0 0 0 0 1 => at index 2, max = 28
// 0 0 0 0 0 => at index 3, max = 49
// 0 0 0 0 0 => at index 4, max = 511
// valid condition: same state in previous index, then it means we have a even count for all letters within the middle substring.14
var count = new Map(); // <mask, first_idx>17
for (var i = 0; i < s.length; i++) {18
if (t.indexOf(s[i]) >= 0) {19
var j = t.indexOf(s[i]);20
mask = mask ^ (1 << j);22
if (!count.has(mask)) {25
// substring is from [prevIdx+1, i];26
res = Math.max(res, i - count.get(mask));