Easy Bitmasking O(n) Solution | C++
Solved using Bitmasking!\nSimple O(n)\n\nclass Solution {\npublic:\n    int longestAwesome(string s) {\n        int n=s.size(),ans=0;\n        vector<int> mask(
Solved using Bitmasking!\nSimple O(n)\n```\nclass Solution {\npublic:\n    int longestAwesome(string s) {\n        int n=s.size(),ans=0;\n        vector<int> mask(1<<10,-1);\n        vector<int>count(10);\n        mask[0]=-1;\n        for(int i=0;i<n;i++){\n            count[s[i]-\'0\']++;\n            int temp=0;\n            for(int j=0;j<10;j++){\n                if(count[j]&1)temp|=(1<<j);\n            }\n            int req=0,chk=0;\n            for(int j=0;j<10;j++){\n                if((temp)&(1<<j))req|=(1<<j),chk++;\n            }\n            if(chk<=1){\n                ans=max(ans,i+1);\n            }\n            else{\n                if(mask[req]!=-1)ans=max(ans,i-mask[req]+1);//all zero\n                for(int j=0;j<10;j++){\n                    //jth bit is one and else zero\n                    int Z=0;\n                    if(temp&(1<<j)){\n                        Z=req^(1<<j);\n                    }else{\n                        Z=req|(1<<j); \n                    }\n                    if(mask[Z]!=-1)ans=max(ans,i-mask[Z]);\n                }                \n            }\n            if(mask[temp]==-1)\n                mask[temp]=i;\n            // cout<<i<<" "<<ans<<endl;\n        }\n        return ans;\n    }\n};\n```
[]