Python O(N) solution with explanation
A substring is palindrome if all the numbers occurs even number of times or only one number occurs odd number of times.\n\nLet \'n\' represent the integer corre
A substring is palindrome if all the numbers occurs even number of times or only one number occurs odd number of times.\n\nLet \'n\' represent the integer corresponding to the bit vector whether count of the digit k is even or odd.\n\n\'0010100010\' is the bit vector indicating that counts of digits 1, 5 and 7 are odd and the rest are even.\n\nAt each index i, update n by toggling the s[i]-th bit because if count of s[i] increments by 1 the bit toggles.\nKeep a map from n to the last i.\n\nIf all the digits in the palindrome i to j occurs even number of times then n(i) = n(j+1). Thus check if n(i) has been seen earlier.\n\nTo check if any one digit occurs in odd number of times, for each digit j toggle the j-th bit in n(i) (call it m(i)) and check if we have seen m(i) earlier.\n\n```\nclass Solution(object):\n    def longestAwesome(self, s):\n        n = 0\n        pos_map = {0:len(s)}\n        \n        max_len = 1\n        \n        for i in range(len(s)-1, -1, -1):\n            n = n ^ (1 << int(s[i]))\n            \n            if n in pos_map:\n                max_len = max(max_len, pos_map[n]-i)\n                \n            for j in range(10):\n                m = n ^ (1 << j)\n                if m in pos_map:\n                    max_len = max(max_len, pos_map[m]-i)\n                    \n            if n not in pos_map:\n                pos_map[n] = i\n        \n        return max_len
[]