✅ One Line Solution
(Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1 - One Pass Using setdefault()\nTime co
(Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1 - One Pass Using setdefault()\nTime complexity: $$O(n)$$. Space complexity: $$O(26)$$.\n```\nclass Solution(object):\n    def maxLengthBetweenEqualCharacters(self, s):\n        return (lambda d:max(i-d.setdefault(c,i)-1 for i,c in enumerate(s)))({})\n```\n\n# Code #2 - One Pass Using update()\nTime complexity: $$O(n)$$. Space complexity: $$O(26)$$.\n```\nclass Solution(object):\n    def maxLengthBetweenEqualCharacters(self, s):\n        return (lambda d:max(i-d[c]-1 if c in d else d.update({c:i}) or -1 for i,c in enumerate(s)))({})\n```\n\n# Code #3 - Two Passes\nTime complexity: $$O(2*n)$$. Space complexity: $$O(26)$$.\n```\nclass Solution(object):\n    def maxLengthBetweenEqualCharacters(self, s):\n        return (d:={c:i for i,c in enumerate(s)}) and max(d[c]-i-1 for i,c in enumerate(s))\n```\n\n# Code #4 - Two Passes Without Walrus\nTime complexity: $$O(2*n)$$. Space complexity: $$O(26)$$.\n```\nclass Solution(object):\n    def maxLengthBetweenEqualCharacters(self, s):\n        return (lambda d:max(d[c]-i-1 for i,c in enumerate(s)))({c:i for i,c in enumerate(s)})\n```\n\n# Code #5 - 26 Passes\nTime complexity: $$O(26*n)$$. Space complexity: $$O(26)$$.\n```\nclass Solution(object):\n    def maxLengthBetweenEqualCharacters(self, s):\n        return max(s.rfind(c)-s.find(c)-1 for c in set(s))\n```\n\n# Code #6 - Slow Approach\nTime complexity: $$O(n^2)$$. Space complexity: $$O(1)$$.\n```\nclass Solution(object):\n    def maxLengthBetweenEqualCharacters(self, s):\n        return max(i-s.find(c)-1 for i,c in enumerate(s))\n```\n\n# Code #7 - Regular Expression\n```\nclass Solution(object):\n    def maxLengthBetweenEqualCharacters(self, s):\n        return max(len(m[1]) if (m:=search(c+\'(.*)\'+c,s)) else -1 for c in set(s))\n```\n\n# Code #8 - Regular Expression Without Walrus\n```\nclass Solution(object):\n    def maxLengthBetweenEqualCharacters(self, s):\n        return max((lambda m:len(m[1]) if m else -1)(search(c+\'(.*)\'+c,s)) for c in set(s))\n```
['Hash Table', 'String', 'Python', 'Python3']