<p>You are given a string <code>s</code>. An <strong>awesome</strong> substring is a non-empty substring of <code>s</code> such that we can make any number of swaps in order to make it a palindrome.</p>

<p>Return <em>the length of the maximum length <strong>awesome substring</strong> of</em> <code>s</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;3242415&quot;
<strong>Output:</strong> 5
<strong>Explanation:</strong> &quot;24241&quot; is the longest awesome substring, we can form the palindrome &quot;24142&quot; with some swaps.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;12345678&quot;
<strong>Output:</strong> 1
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;213123&quot;
<strong>Output:</strong> 6
<strong>Explanation:</strong> &quot;213123&quot; is the longest awesome substring, we can form the palindrome &quot;231132&quot; with some swaps.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
	<li><code>s</code> consists only of digits.</li>
</ul>

class Solution {
public:
    map<int, int> mp;  

    int longestAwesome(string s) {
        int mask = 0;  
        int n = s.size(), ans = 0;
        mp[0] = -1;

        for (int j = 0; j < n; j++) {
            if (s[j] == '0') {
                mask ^= (1 << 0);  
            } else if (s[j] == '1') {
                mask ^= (1 << 1);  
            } else if (s[j] == '2') {
                mask ^= (1 << 2);  
            } else if (s[j] == '3') {
                mask ^= (1 << 3); 
            } else if (s[j] == '4') {
                mask ^= (1 << 4);  
            }
            else if (s[j] == '5') {
                mask ^= (1 << 5);  
            }
            else if (s[j] == '6') {
                mask ^= (1 << 6);  
            }
            else if (s[j] == '7') {
                mask ^= (1 << 7);  
            }
            
            else if (s[j] == '8') {
                mask ^= (1 << 8);  
            }
            else if (s[j] == '9') {
                mask ^= (1 << 9);  
            }
    
            if (mp.find(mask) != mp.end()) {
                int index = mp[mask];
                ans = max(ans, j - index); 
            }
            else {
                mp[mask] = j; 
            }
            
            for(int k=0; k<=9; k++){
                 int cur=mask; 
                 cur =cur^(1<<k);
                 if (mp.find(cur) != mp.end()) {
                     int idx = mp[cur];
                     if((j-idx)%2==1){
                        ans = max(ans, j- idx); 
                     }
                     
                }   
            }

        }

        return ans;
    }
};

14900