Bitmask + prefix xor (Explaination)
if looked carefully, this question reduces to the problem which is a slight variation of the problem\nhttps://leetcode.com/problems/number-of-wonderful-substrin
if looked carefully, this question reduces to the problem which is a slight variation of the problem\nhttps://leetcode.com/problems/number-of-wonderful-substrings/\n\nif we want to make a substing palindrome, it either could have even length or odd length, for even length palindrome, we need all the constituting characters to occur even number of times, \nand to have a palindrome of odd length, we need all the other characters to occur even number of times except that one character at the middle which will occur once. \n\nSo, at last the problem reduces to finding the length of longest substring that has at most 1 character that occurs odd number of times.\n\nhere is the solution, we will be storing the first index of every prefix xor.\n\nclass Solution {\npublic:\n\n    int longestAwesome(string s) {\n\t\n        // i think the question reduces to finding the longest substring having at at most one character that occurs odd number of times\n        \n        int mask=0;\n        unordered_map<int,int> m;\n        \n        m[0]=-1; // prefix xor and its index\n        int ans=INT_MIN;\n        \n        for(int i=0;i<s.size();i++)\n        {\n            mask^= (1<<(s[i]-\'0\'));\n            \n            if(m.count(mask^0))\n                ans= max(ans,i-m[mask^0]);\n            \n            for(int k=0;k<32;k++)\n            {\n                int copy= mask;\n                \n                copy^=(1<<k);\n                \n                if(m.count(copy))\n                    ans= max(ans,i-m[copy]);\n            }\n            if(m.count(mask)==0)\n                m[mask]=i;\n        }\n        return ans;\n    }\n};
['C', 'Bitmask']