JavaScript hashmap
\nvar maxLengthBetweenEqualCharacters = function(s) {\n    let map = new Map();//map {char: index}\n    let maxDist = -1;\n    for (let i = 0; i < s.length; i++
```\nvar maxLengthBetweenEqualCharacters = function(s) {\n    let map = new Map();//map {char: index}\n    let maxDist = -1;\n    for (let i = 0; i < s.length; i++){\n        let ch = s.charAt(i);\n        if (!map.has(ch)){\n            map.set(ch, i);\n        } else {\n            let lastIdx = map.get(ch);\n            let dist = i-lastIdx-1 // excluding duplicate letters\n            maxDist = Math.max(maxDist, dist);\n        }\n    }\n    return maxDist;\n};\n```
[]