Java Solution for beginners O[N].....
Intuition\n Describe your first thoughts on how to solve this problem. \n    Store the first index and find last index and update the maximum distance.\n# Appro
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n    Store the first index and find last index and update the maximum distance.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n    0.Creat a class or any pair that holds two parameters \n    1. The index of first occurrence of a character and \n    2. boolean value that specifies the character already occurred or not.\n    3.Create a list of size 26 of type "Your ClassName".\n    4.Traverse the String and apply two checks.\n        i)If it is the first time the character occurred then update the specified index object.\n        ii)If it is not the first occurrence, apply math to get distance between them [ currentIndex - firstIndex - 1] and compare it with maxLength and update it. \n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    N = Length of the String.\n    then => TC : O(N) + 26 => O(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    M = 26, since creating list of size 26.\n    SC : O(M)\n# Code\n```\nclass Solution {\n    class LastIndexTracker {\n        private int firstIndex;\n      \n        private boolean isFirstIndexFilled = false;\n\n        //Default Constructor\n        public LastIndexTracker() {}\n\n        //Setter\n        public void setFirstIndex(int firstIndex) {\n            this.firstIndex = firstIndex;\n        }\n\n        public void setIsFirstIndexFilled(boolean isFirstIndexFilled) {\n            this.isFirstIndexFilled = isFirstIndexFilled;\n        }\n\n        //Getter\n        public int getFirstIndex() {return firstIndex;}\n\n        public boolean getIsFirstIndexFilled() {return isFirstIndexFilled;}\n    }\n\n    public int maxLengthBetweenEqualCharacters(String s) {\n        int maxLength = -1;\n\n        List<LastIndexTracker> list = new ArrayList<>();\n\n        for(int i = 0;i<26;i++) {\n            list.add(new LastIndexTracker());\n        }\n       \n        for(int i = 0;i<s.length();i++) {\n          \n            if (!list.get(s.charAt(i)-\'a\').getIsFirstIndexFilled()) {\n                list.get(s.charAt(i)-\'a\').setFirstIndex(i);\n                list.get(s.charAt(i)-\'a\').setIsFirstIndexFilled(true);\n            } else {\n                int max = i- list.get(s.charAt(i)-\'a\').getFirstIndex() - 1;\n                if (max > maxLength) {\n                    maxLength = max;\n                }\n            }\n\n        }\n        return maxLength;\n    }\n}\n```
['Java']