Simple JAVA Solution|| HashMap || O(n) time|| with Explanation
Intuition\n Describe your first thoughts on how to solve this problem. \n- Store each char along with their position in a HashMap.\n- If a char occurs again, ca
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Store each char along with their position in a HashMap.\n- If a char occurs again, calc their index diffrences.\n- return the max difference.\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(min(n, k))\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int maxLengthBetweenEqualCharacters(String s) {\n        int res=-1;\n        HashMap<Character,Integer> hm=new HashMap<>();\n        for(int i=0;i<s.length();i++){\n            char c=s.charAt(i);\n            if(hm.containsKey(c))\n                res=Math.max(res,i-hm.get(c)-1);\n            else\n                hm.put(c,i);\n        }\n\n        return res;\n    }\n}\n```
['Java']