[Python3] via dictionary
Memoize the first occurrence of a character. \n\nclass Solution:\n    def maxLengthBetweenEqualCharacters(self, s: str) -> int:\n        ans = -1\n        seen 
Memoize the first occurrence of a character. \n```\nclass Solution:\n    def maxLengthBetweenEqualCharacters(self, s: str) -> int:\n        ans = -1\n        seen = {}\n        for i, c in enumerate(s): \n            if c in seen: ans = max(ans, i - seen[c] - 1)\n            seen.setdefault(c, i)\n        return ans \n```
['Python3']