Largest Substring Between Two Equal Characters LeetCode solution in JavaScript

1
var maxLengthBetweenEqualCharacters = function (s) {
2
const map = new Map();
3
let max = -1;
4
for (let i = 0; i < s.length; i++) {
5
if (map.has(s[i])) {
6
max = Math.max(max, i - (map.get(s[i]) + 1));
7
} else {
8
map.set(s[i], i);
9
}
10
}
11
return max;
12
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0