from O(n^2) to O(N)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n# Approach\n Describe your approach to solving the problem. \n1.itreate a lop form 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.itreate a lop form 0 to size-1\n2.again for every index itreate a lop form 0 to size-1\n3.when ever we found index equal subtract index of second loop from index of 1st loop minus 1\nstore the max difference of these two index\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N^2)\nfirst approch\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1) first approch\n\n\n# Code\n```\nclass Solution {\npublic:\n    int maxLengthBetweenEqualCharacters(string s) {\n        int ans=0,f=0;\n        for(int i=0;i<s.size();i++){\n            for(int j=i+1;j<s.size();j++){\n                if(s[i]==s[j]){\n                ans=max(ans,j-i-1);\n                f=1;\n                }\n            }\n        }\n        if(f)\n        return ans;\n\n        return -1;\n    }\n};\n```
['C++']