O(N) 100% beats C++ using map
\n# Approach\n1. Intitialize max=-1 and a map for storing char\n2. If the char in string s arrives for the first time then we will push it into map as  \n3. If 
\n# Approach\n1. Intitialize max=-1 and a map for storing char\n2. If the char in string s arrives for the first time then we will push it into map as <char,index of char > \n3. If the char arrives again then it will be already present in map.\nSo, we will calculate the length of substring by i-map[s[i]]-1.(we subtracted 1 because we don\'t want to include the equal characters).\n4. Now compare the length with max and update max if len is greater.\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    int maxLengthBetweenEqualCharacters(string s) {\n        unordered_map<char,int>map;\n        int n=s.size();\n        int i=0,max=-1;\n        while(i<n){\n            if(map.find(s[i])!=map.end()){\n                int len=i-map[s[i]]-1;\n                if(max<len)\n                    max=len;\n                }\n            else{\n            map[s[i]]=i;}\n            i++;\n        }\n        return max;\n    }\n};\n```
['C++']