Yet another Python solution O(n)
Create a map to keep the first occurrence of the character in the string s.\n2. If the next character is already on the map - we update the max distance.\n\nCom
1. Create a map to keep the first occurrence of the character in the string ```s```.\n2. If the next character is already on the map - we update the max distance.\n\nComplexity O(N) - one loop\nMemory: at first sight, it is also O(N). But if the number of characters is limited by the English alphabet, then to store the map we need only O(26) which is O(1).\n\n*Please upvote if you like for motivation and karma :)*\n\n```\nclass Solution:\n    def maxLengthBetweenEqualCharacters(self, s: str) -> int:\n        \n        charToID = dict()\n        maxDist = -1\n        \n        for i, ch in enumerate(s):\n            if ch not in charToID:\n                charToID[ch] = i\n            else:\n                maxDist = max(maxDist, i - charToID[ch] -1)\n        \n        return maxDist\n```
['Python']