[Java/Python 3] One pass O(n) 11/4 liners w/ brief explanation and analysis.
Loop through the input string s\n1. Store the first index of the substring between same characters;\n2. If current character seen before, compute the length of 
Loop through the input string `s`\n1. Store the first index of the substring between same characters;\n2. If current character seen before, compute the length of the sustring between them and update the max length; \n```java\n    public int maxLengthBetweenEqualCharacters(String s) {\n        int[] indices = new int[26];\n        int maxLen = -1;\n        for (int i = 0; i < s.length(); ++i) {\n            int idx = s.charAt(i) - \'a\';\n            if (indices[idx] > 0) {\n                maxLen = Math.max(maxLen, i - indices[idx]);\n            }else {\n                indices[idx] = i + 1;\n            }\n        }\n        return maxLen;\n    }\n```\n```python\n    def maxLengthBetweenEqualCharacters(self, s: str) -> int:\n        maxLen, indices = -1, {}\n        for i, c in enumerate(s):\n            maxLen = max(maxLen, i - indices.setdefault(c, i + 1))\n        return maxLen        \n```\n**@StefanPochmann**\'s solution with explanation:\n\n```python\n    def maxLengthBetweenEqualCharacters(self, s: str) -> int:\n        return max(map(sub, count(), map({}.setdefault, s, count(1))))\n```\n@rock It\'s really exactly what yours does. You create a dictionary and then use its `setdefault` method to get the values of `setdefault(s[0], 1), setdefault(s[1], 2), setdefault(s[2], 3)`, etc. That\'s exactly what my second `map` does, too. And you subtract those results from `0, 1, 2,` etc. That\'s exactly what my first `map` does, too. Yours is probably clearer already because the `setdefault` and the subtraction are done in the same small expression, whereas I do them in independent maps. Here\'s a middle-ground solution:\n```python\ndef maxLengthBetweenEqualCharacters(self, s: str) -> int:\n    indices = {}.setdefault\n    return max(i - indices(c, i + 1)\n               for i, c in enumerate(s))\n```\nMight be clearer to store the actual indices and instead subtract from the index difference:\n```python\ndef maxLengthBetweenEqualCharacters(self, s: str) -> int:\n    indices = {}.setdefault\n    return max(i - indices(c, i) - 1\n               for i, c in enumerate(s))\n```\nWe can also take the `- 1` out even further, making it a bit faster but perhaps less clear:\n```python\ndef maxLengthBetweenEqualCharacters(self, s: str) -> int:\n    indices = {}.setdefault\n    return max(i - indices(c, i)\n               for i, c in enumerate(s)) - 1\n```\n\n**Analysis:**\n\nTime: `O(n)`, space: `O(1)`, where `n = s.length()`.
[]