<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:
    int longestAwesome(string s) {
        //3 = 001000
        //2 = 001100 (0100)
        //4 = 011100
        //2 = 011000
        //4 = 001000
        //1 = 001010
        unordered_map<int, int> bitmask;
        for (int i = 0; i < 10; i++) {
            bitmask[i] = pow(2, i);
        }
        vector<int> prev(1024, -1);
        int prefixXor = 0, ans = INT_MIN;
        for (int i = 0; i < s.length(); i++) {
            int currVal = s[i] - '0';
            // cout << " curr Val " << currVal << endl;
            prefixXor ^= bitmask[currVal];
            // cout << "prefixXor " << prefixXor << " and val " << prev[prefixXor] << endl;
            if (prefixXor != 0 && prev[prefixXor] == -1) {
                //  cout << " setting prefixXor " << prefixXor << " " << i << endl;
                prev[prefixXor] = i;
            } else if (prefixXor == 0) {
                //current index string is a palindrom
                ans = i + 1;
            }
            for (int j = 0; j < 10; j++) {
                int bitWithOdd = prefixXor ^ bitmask[j];
                // cout << " j = " << j << " bitWithOdd " << bitWithOdd << endl;
                if (prev[bitWithOdd] != -1 || bitWithOdd == 0) {
                    // cout << " prev for " << bitWithOdd << " exists = " << prev[bitWithOdd] << endl;
                    ans = max(ans, i - prev[bitWithOdd]);
                }
            }
        }

        return ans;   
    }
};
13000