C++ & Java || Explained - Max diff of last occurrence & curr char index
Approach\n- Track the last occurance index of each char \n- Then traverse from the front and check the diff of each char index with there last occurance index\n
# Approach\n- Track the last occurance index of each char \n- Then traverse from the front and check the diff of each char index with there last occurance index\n- Keep tracking the max.\n\n# C++\n```\nint maxLengthBetweenEqualCharacters(string s) {\n    int last[26] = {0}, ans = -1;\n    for(int i = 0; i < s.size(); ++i) last[s[i] - \'a\'] = i;\n    for(int i = 0; i < s.size(); ++i) ans = max(ans, last[s[i] - \'a\'] - i - 1);\n    return ans;\n}\n```\n\n# Java\n```\npublic int maxLengthBetweenEqualCharacters(String s) {\n    int[] last = new int[26];\n    int ans = -1;\n    for(int i = 0; i < s.length(); ++i) last[s.charAt(i) - \'a\'] = i;\n    for(int i = 0; i < s.length(); ++i) ans = Math.max(ans, last[s.charAt(i) - \'a\'] - i - 1);\n    return ans;\n}\n```\n\n\n---\n\n<b>Here is an article of my last interview experience - A Journey to FAANG Company, I recomand you to go through this to know which all resources I have used & how I cracked interview at Amazon:\nhttps://leetcode.com/discuss/interview-experience/3171859/Journey-to-a-FAANG-Company-Amazon-or-SDE2-(L5)-or-Bangalore-or-Oct-2022-Accepted\n\n---
['C++', 'Java']