C++ | One Pass Map Solution O(n)
\nclass Solution {\npublic:\n    int maxLengthBetweenEqualCharacters(string s) {\n        std::unordered_map<char, int> mp; // key: character, value: least inde
```\nclass Solution {\npublic:\n    int maxLengthBetweenEqualCharacters(string s) {\n        std::unordered_map<char, int> mp; // key: character, value: least index of character in s\n        int len = -1;\n        for(int i = 0; i < s.length(); i++) {\n            if(mp.count(s[i])) len = max(len, i - mp[s[i]] - 1);\n            else mp[s[i]] = i;\n        }\n        return len;\n    }\n};\n```
[]