Python 3, dict, 24 ms, explained
Use a dict to store the array index;\nIterate the dict values, find the max difference among the chars that appear more than once.\n~~~\nclass Solution:\n    de
Use a dict to store the array index;\nIterate the dict values, find the max difference among the chars that appear more than once.\n~~~\nclass Solution:\n    def maxLengthBetweenEqualCharacters(self, s: str) -> int:\n        mydict = collections.defaultdict(list)\n        result = -1\n        for index, char in enumerate(s):\n            mydict[char].append(index)\n        for key, value in mydict.items():\n            if len(value) > 1:\n                tmp = value[-1] - value[0] - 1\n                result = max(tmp, result)\n        return result\n~~~
['Python', 'Python3']