This is a very Easy question
Intuition\nThis is a very question all you need to think is that the only way possible is get the answer is to know the first and last occurences of the each al
# Intuition\nThis is a very question all you need to think is that the only way possible is get the answer is to know the first and last occurences of the each alphabets and taking the maximum among them\n\n# Approach\nWe take a array where we store the index (1 based indexing because 0th char will store 0 which is same for empty characters) of first occurence of each alphabet and every time that alphabet is again found we calculate the length of the substring between them take the maximum among them as result\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int maxLengthBetweenEqualCharacters(string s) {\n        int arr[27]={0};\n        int res=-1;\n        for(int i=0;i<s.size();i++)\n        {\n        if(arr[s[i]-\'a\']==0)\n        arr[s[i]-\'a\']=i+1;//because we use 1s based indexing\n        res=max(res,(i+1-arr[s[i]-\'a\']-1));\n//we subtract 1 because the character itself is not included in the  substring \n        }\n        return res;\n        \n    }\n};\n```
['C++']