Most optimal solution using hashmap
Complexity
Time complexity:O(N)

Space complexity:O(1)
Code

# Complexity
- Time complexity:O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def maxLengthBetweenEqualCharacters(self, s: str) -> int:
        d={}
        for i in range(len(s)):
            if s[i] in d:
                d[s[i]].append(i)
            else:
                d[s[i]]=[i]
        maxi=-1
        for i,j in d.items():
            if len(j)>1:
                maxi=max(maxi,d[i][-1]-d[i][0]-1)
        return maxi
```
['Hash Table', 'String', 'Python3']