bitmask/bitmap solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define CountSetBits __builtin_popcount\n#define nl cout<<"\\n"\nint ctoi(char c){\n    return c-\'0\';\n}\n\nclass Solution {\npublic:\n    int longestAwesome(string s) {\n        /*\n            prefix arr, pre[i] = s[0:i] = freq parity(even or odd freq) of digits 0-9\n            if pre[i]==0 or has only 1 set bit, means s[0:i] is awesome, ans=i+1\n            \n            pre[i] ^ pre[j] == x == 0 or 1 set bit\n            pre[i] ^ x == pre[j], loop on x=[2^0, 2^10], x<<=1\n            \n            xor table\n            0 ^ 0 = 0\n            0 ^ 1 = 1\n            1 ^ 0 = 1\n            1 ^ 1 = 0\n        */\n\n\n        int cur=0, n = s.size();\n        unordered_map<int, int> preMap; auto&m=preMap;// map[val] -> ind\n        vector<int> pre(n); \n        for(int i=0; i<n; i++){\n            auto c = s[i];\n            int x = ctoi(c);\n            cur ^= (1<<x);\n\n            if(preMap.find(cur) == preMap.end())\n                preMap[cur] = i;\n            pre[i] = cur;\n        }\n\n        int ans=0; \n        for(int i=0; i<n; i++){\n            if(pre[i] == 0 or CountSetBits(pre[i])==1){\n                ans = i+1;\n            }else{\n                if(m.find(pre[i]) != m.end()){\n                    int j = preMap[pre[i]];\n                    ans = max(ans, i-j);\n                    if(ans%2==0) ans++;\n                }\n                int x = 1; \n                while(x <= 512){\n                    int xorr = pre[i]^x;\n                    if(preMap.find(xorr) != preMap.end()){\n                        int j = preMap[xorr];                        \n                        ans = max(ans, i-j);\n                    }\n                    x <<= 1;\n                }\n            }\n        }\n\n        return ans;\n    }\n};\n```
['C++']