[Python] blazingly fast (208 ms, 99% runtime) while short and simple
Two simple ideas that take advantage of long test scenarios:\n\n1. In the first loop, create dictionaries dictF(orward) and dictB(ackward) that contain first an
Two simple ideas that take advantage of long test scenarios:\n\n1. In the first loop, create dictionaries dictF(orward) and dictB(ackward) that contain first and last occurances of cumulative XOR for bitwise coding of digits - the coding is explained very well in other solutions in the discussion. [E.g., see this great post from votrubac.](https://leetcode.com/problems/find-longest-awesome-substring/discuss/779893/C%2B%2BJavaPython3-with-picture-(similar-to-1371))\n2. In the return statement, browse dictF and dictB for the largest distance between the indices. \n\nTime saving: finding max at every step is no longer needed. Instead, we need to populate additional dictionary.\n\n```\nclass Solution:\n    def longestAwesome(self, s: str) -> int:\n        \n        digits=[512 >> move for move in range(11)]\n        xor, dictF, dictB=0, {0:-1}, {0:-1}\n        \n        for i in range(len(s)):\n            xor=xor ^ (1 << int(s[i]))\n            if xor not in dictF:\n                dictF[xor]=i\n            dictB[xor]=i\n\n        return max([(ind-dictF[val ^ digit]) \\\n                            for val, ind in dictB.items() \\\n                            for digit in digits \\\n                            if digit ^ val in dictF])\n```
['Python']