C++ Bit
It would be better to represent the "key" using integer. The idea behind is the same.\n\n\nclass Solution {\npublic:\n    int longestAwesome(string s) {\n      
It would be better to represent the "key" using integer. The idea behind is the same.\n\n```\nclass Solution {\npublic:\n    int longestAwesome(string s) {\n        string key(10, \'0\');\n        unordered_map<string, vector<int>> mp;\n        mp[key].push_back(-1);\n        \n        for(int i=0; i<s.size(); i++) {\n            int a = s[i] - \'0\';\n            if(key[a] == \'0\') key[a] = \'1\';\n            else key[a] = \'0\';\n            mp[key].push_back(i);\n        }\n        \n        int ans = 1;\n        for(auto &[k, v] : mp) {\n            if(v.size() > 1) ans = max(ans, v.back() - v[0]);\n            \n            string cp = k;\n            for(int j=0; j<10; ++j) {\n                string cp = k;\n                if(k[j] == \'1\') cp[j] = \'0\';\n                else cp[j] = \'1\';\n                \n                if(mp.count(cp)) {\n                    auto v2 = mp[cp];\n                    ans = max(ans, v.back() - v2[0]);\n                    ans = max(ans, v2.back() - v[0]);\n                }\n            }\n        }\n        \n        return ans;\n    }\n};\n```
[]