Beats 96% Bitmask Prefix Sum (Find 1 Off Neighbors)
\n\nclass Solution {\npublic:\n    int longestAwesome(string s) {\n        int num = 0;\n        vector<int> maxes(1024,-1);\n        vector<int> mins(1024,s.le
\n```\nclass Solution {\npublic:\n    int longestAwesome(string s) {\n        int num = 0;\n        vector<int> maxes(1024,-1);\n        vector<int> mins(1024,s.length());\n        maxes[0] = 0; mins[0] = 0;\n        for(int i = 0; i < s.length(); i++){\n            int mask = 1 << (s[i]-\'0\');\n            num ^= mask;\n            maxes[num] = max(maxes[num],i+1);\n            mins[num] = min(mins[num],i+1);\n        }\n        int sol = 1;\n        for(int i = 0; i < maxes.size(); i++){\n            if(maxes[i] == -1) continue;\n            for(int j = 0; j <= 9; j++){\n                int newI = i ^ (1 << j);\n                if(mins[newI] == s.length()) continue;\n                if(maxes[i] <= mins[newI]) continue;\n                if((maxes[i]-mins[newI])%2!=1) continue;\n                sol = max(sol, maxes[i]-mins[newI]);\n            }\n            sol = max(sol,maxes[i]-mins[i]+1);\n        }\n        return min(sol, (int)s.length());\n    }\n};\n```
['C++']