Without BITMASKING || C++
cnt(j) --> number of occurences of j, till ith index.\ncur_state --> string to represent the current state.\n\ncur_state(j) ->0 ==> j appears an even number of 
cnt(j) --> number of occurences of j, till ith index.\ncur_state --> string to represent the current state.\n\ncur_state(j) ->0 ==> j appears an even number of times till ith index.\ncur_state(j) ->1 ==> j appears an odd number of times till ith index.\n\nLet cur_state for any arbitary index i = "0100000000"\nThis means that 1 has appeared an odd number of times, till ith index and all other digits appeared \n0 number of times.\n\nSince we want to find longest substring, for which the substring could be rearranged to a palindrome .\nThis is possible in 2 cases\ncase 1: if all the distinct characters in the substring appears an even number of time\ncase 2: if all the distinct characters in the substring appears an even number of time, except for one character.\n\nany state that we encouter is stored in a hash map against the index where that state occured, if the same state  or a state such that only one index is altered occurs later in the traversal ==> the substring between them including the cur index and not including the prev index is a valid answer.\nJust find the maximum length among all such valid answers.\n\n``\nclass Solution {\npublic:\n    int longestAwesome(string s) {\n        \n        unordered_map<string, int>mp; // (state, earliest index where this state was seen).\n        int n = s.size();\n        \n        mp["0000000000"] = -1; \n        \n        int ans = 0;\n        \n        int cnt[10] = {};\n        \n        for(int i = 0; i<n; i++){\n            \n            cnt[s[i]-\'0\']++; // incrementing the count of cur_character.\n            \n            string cur_state = ""; // stores the cur_state.\n            \n            for(int j = 0; j<10; j++){\n                \n                if(cnt[j] % 2 ==0){\n                    \n                    cur_state+=\'0\';\n                }\n                else{\n                    cur_state+=\'1\';\n                }\n            }\n            \n            // Case 1 : if same to same state was there earlier ==> all chars even substring ==> yes a palindrome.\n            \n            if(mp.find(cur_state) != mp.end()){\n                ans = max(ans, i - mp[cur_state]);\n                \n                \n            }\n            \n            else{\n                mp[cur_state]  = i;\n            }\n            \n          \n           \n            \n            // Case 2 : if only one change..\n            \n            for(int j = 0; j<10; j++){\n                \n                \n                // changing the state for the time being..\n                \n                if(cur_state[j]==\'0\'){\n                    cur_state[j] = \'1\';\n                }\n                else{\n                    cur_state[j] = \'0\';\n                }\n                \n                if(mp.find(cur_state) != mp.end()){\n                    ans = max(ans, i - mp[cur_state]);\n                }\n                \n                // changing it back to original state.\n                \n                 if(cur_state[j]==\'0\'){\n                    cur_state[j] = \'1\';\n                }\n                \n                else{\n                    cur_state[j] = \'0\';\n                }\n                \n                \n                 \n            }\n            \n           \n            \n            \n        }\n        \n     \n        return ans;\n    }\n};\n``
[]