JS-Easy to understand for beginners as well
\nvar maxLengthBetweenEqualCharacters = function (s) {\n\n    const map = new Map();\n    let max = -1;\n\n    for (let i = 0; i < s.length; i++) {\n\n        i
```\nvar maxLengthBetweenEqualCharacters = function (s) {\n\n    const map = new Map();\n    let max = -1;\n\n    for (let i = 0; i < s.length; i++) {\n\n        if (map.has(s[i])) {\n            max = Math.max(max, i - (map.get(s[i]) + 1));\n        } else {\n            map.set(s[i], i)\n        }\n\n    }\n    \n    return max;\n};\n```\n\n**Since it consists only lowercase english letters, we could use constant space**\n```\n/**\n * @param {string} s\n * @return {number}\n */\nvar maxLengthBetweenEqualCharacters = function (s) {\n    let start = 0;\n    const end = s.length - 1;\n    let max = -1;\n    const charArr = new Array(26).fill(-1);\n\n\n    while (start <= end) {\n        const pos = s[start].charCodeAt() - 97;\n\n        if (charArr[pos] !== -1) {\n            // calc the characs in between if any of the chars appeared again\n            max = Math.max(start - charArr[pos] - 1, max);\n        } else {\n            // store the first occurance\n            charArr[pos] = start;\n        }\n        start++;\n    }\n\n    return max;\n\n};\n```
['JavaScript']