optimized
Intuition\n Describe your first thoughts on how to solve this problem. \nfor max length of substring 2 index must be equal \n\n# Approach\n Describe your approa
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nfor max length of substring 2 index must be equal \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.Take a map\n2. search if that index is alredy present in map or not if not then store it with value as index number otherwise subtract these with index stored in map\n3. take a flag for checking wheter any number is repeated or not \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n# Code\n```\nclass Solution {\npublic:\n    int maxLengthBetweenEqualCharacters(string s) {\n        int ans=0,f=0;\n        unordered_map<char,int>m;\n        for(int i=0;i<s.size();i++){\n            if(m.find(s[i])!=m.end()){\n            \n                f=1;\n                ans=max(ans,i-m[s[i]]-1);\n            }\n            else\n            m[s[i]]=i;\n\n\n        }\n        if(f)\n        return ans;\n        return -1;\n    }\n};\n```
['C++']