Using Array! Beats 100% Java!
Intuition\n Describe your first thoughts on how to solve this problem. The problem was quite eassy and intutional..upon reading for the first time just relized 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->The problem was quite eassy and intutional..upon reading for the first time just relized it just demands us to keep track of the last and first position of the characters and then it is just a loop to check the max distance between these two position for every duplicate elements.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->I employed an array to track the indices of character appearances in the string. Initially, I traversed the string to record the first occurrence of each character in the array. Subsequently, by iterating backward through the string, I located the last appearance of each character. Whenever an unencountered character from the end matched its initial appearance, I calculated the distance between the two occurrences. Through this process, I efficiently determined the maximum separation between equal characters, updating a variable to hold this length.s\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->Overall, the time complexity of code is O(n), where n is the length of the input string.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->The space complexity of the code is O(1) (constant space), considering the size of the array is not dependent on the input size but on the fixed number of lowercase English letters (26).\n\n# Code\n```\nclass Solution {\n    public int maxLengthBetweenEqualCharacters(String s) {\n        int[] arr=new int[26];\n        Arrays.fill(arr,-1);\n        int min=-1;\n        int j=0;\n        for(char ch:s.toCharArray()){\n            if(arr[ch-\'a\']==-1){\n                arr[ch-\'a\']=j;\n            }\n            j++;\n        }\n        for(int i=s.length()-1;i>=0;i--){\n            char ch=s.charAt(i);\n            if(arr[ch-\'a\']!=-1){\n                min=Math.max(min,i-arr[ch-\'a\']-1);\n                arr[ch-\'a\']=-1;\n            }\n        }\n        return min;\n\n        \n    }\n}\n```
['Array', 'Hash Table', 'String', 'Java']