human
I found an interesting problem on https://leetcode.com/problems/find-longest-awesome-substring/:
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
 
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form the palindrome "24142" with some swaps.

Example 2:
Input: s = "12345678"
Output: 1

Example 3:
Input: s = "213123"
Output: 6
Explanation: "213123" is the longest awesome substring, we can form the palindrome "231132" with some swaps.

Example 4:
Input: s = "00"
Output: 2

 
Constraints:

1 <= s.length <= 10^5
s consists only of digits.

I tried it in Python, but could not do it. Can you solve it?
assistant
#Here is the Python program you requested.

class Solution:
    def longestAwesome(self, s: str) -> int:
        left_most_masks = {0:-1}
        valid_masks =  {1 << i for i in range(10)} | {0}
        ans = 0
        cur_mask = 0
        
        for idx, x in enumerate(list(s)):
            cur_mask = cur_mask ^ 1 << int(x)
            for valid_mask in valid_masks:
                left_mask = valid_mask ^ cur_mask
                if left_mask in left_most_masks:
                    ans = max(ans, idx - left_most_masks[left_mask])
            if cur_mask not in left_most_masks:
                left_most_masks[cur_mask] = idx
        return ans