TypeScript Solution using Prefix Sum and Bitmask
typescript []\nfunction longestAwesome(s: string): number {\n    // 10 digits -> bitmask of size 10\n    // there are 2 cases for palindrome:\n    // - all char
```typescript []\nfunction longestAwesome(s: string): number {\n    // 10 digits -> bitmask of size 10\n    // there are 2 cases for palindrome:\n    // - all characters appear an even number of times\n    // - 1 character appears an odd number of times\n    \n    // map bitmask to start index\n    const map = new Map<number, number>()\n    let mask = 0\n    let res = 0\n\n    map.set(0, -1)\n    for (let i = 0; i < s.length; i++) {\n        const bit = s.charCodeAt(i) - \'0\'.charCodeAt(0)\n        mask ^= 1 << bit\n\n        if (map.has(mask)) {\n            // matching bitmask so s[map.get(mask) + 1, ..., i] is a palindrome\n            // one with all even, to be exact\n            res = Math.max(res, i - map.get(mask))\n        } else {\n            // want the longest palindrome, so only set if map doesn\'t already\n            // contain mask\n            map.set(mask, i)\n        }\n\n        // check all possible palindromes with the odd one\n        for (let j = 0; j < 10; j++) {\n            const oddMask = mask ^ (1 << j)\n            if (map.has(oddMask)) {\n                // find the substring that only i appears odd number of times\n                res = Math.max(res, i - map.get(oddMask))\n            }\n        }\n    }\n    return res\n};\n```
['TypeScript']