C++ hashmap and bit manipulation with approach
To approach this kind of problem,\n1) think about an iteration that considers each index as a possible end of a substring\n2) think about what a state at each i
To approach this kind of problem,\n1) think about an iteration that considers each index as a possible end of a substring\n2) think about what a state at each iteration needs\n3) understanding if each digit count is divisible by 2 is palidrome specific, and storing the boolean values of this in an array for each digit\n4) understanding that boolean array can be stored using a number and bit manipulation\n5) understanding that there can be all evens (if we saw this state before we can subtract it to get all evens), or consider 1 posible odd and the rest evens, and iterate thru considering each digit as an odd frequency\n\nMy solution can be optimized further by using an array of size 1024 instead of an unordered_map\n```\nclass Solution {\npublic:\n    int longestAwesome(string s) {\n        unordered_map<int, int> prevStates;\n        prevStates[0] = -1;\n        int ans = 0;\n        int curState = 0;\n        for (int i = 0; i < s.size(); ++i) {\n            int digit = s[i] - \'0\';\n            curState ^= 1 << digit;\n            if (prevStates.count(curState)) \n                ans = max(ans, i - prevStates[curState]);\n            else prevStates[curState] = i;\n            for (int j = 0; j < 10; ++j) {\n                int tempState = curState ^ (1 << j);\n                if (prevStates.count(tempState)) \n                    ans = max(ans, i - prevStates[tempState]);\n            }\n        }\n        return ans;\n    }\n};\n```
[]