Largest index difference |  Java | C++
Intuition and approach\nTo get maximum length of substring between two same characters it would be ideal to find the diffrence of the first and last indicies of
# Intuition and approach\nTo get maximum length of substring between two same characters it would be ideal to find the diffrence of the first and last indicies of a character in the given string.\n\n# Complexity\n- Time complexity:\nO(n), n is the size of the given string s\n\n- Space complexity:\nO(26)\n# Code\nJava\n```\nclass Solution {\n    public int maxLengthBetweenEqualCharacters(String s) {\n        int charIndxMp[] = new int[26];\n        Arrays.fill(charIndxMp, -1);\n        int maxSubLen = -1;\n        for(int indx = 0; indx < s.length(); indx++){\n            int currChar = s.charAt(indx) - \'a\';\n            if(charIndxMp[currChar] != -1){\n                maxSubLen = Math.max(maxSubLen, indx - charIndxMp[currChar] - 1);\n            }else\n                charIndxMp[currChar] = indx;\n        }\n        return maxSubLen;\n    }\n}\n```\nC++\n```\nclass Solution {\npublic:\n    int maxLengthBetweenEqualCharacters(string s) {\n        vector<int> charIndxMp(26, -1);\n        int maxSubLen = -1;\n        for(int indx = 0; indx < s.size(); indx++){\n            int currChar = s[indx] - \'a\';\n            if(charIndxMp[currChar] != -1){\n                maxSubLen = max(maxSubLen, indx - charIndxMp[currChar] - 1);\n            }else\n                charIndxMp[currChar] = indx;\n        }\n        return maxSubLen;\n    }\n};\n```
['String', 'C++', 'Java']