<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:
    def longestAwesome(self, s: str) -> int:
        max_len = 0
        mask = 0
        seen = {0: -1}
        # 33445
        for i,c in enumerate(s):
            mask ^= 1 << ord(c) - ord('0')
            last_seen = seen.setdefault(mask, i)

            # the palindrome is i - last_seen + 1
            # or possibly, if the mask has only 1 one,
            # we can use 0
            # 7: 0111
            # 8: 1000
            # x: 1111
            # doesn't this generalize to finding the bit string
            # of 1 difference and finding the max of that?
            for t in range(0,10):
                last_seen = min(last_seen, seen.get(mask ^ (1 << t), i))
            max_len = max(max_len, i - last_seen)
            # print('at i,c', i,c, ' max is now ', max_len, ' last seen: ', last_seen)

        return max_len
17400