Leetcode Problem 1371. Find the Longest Substring Containing Vowels in Even Counts
1371. Find the Longest Substring Containing Vowels in Even Counts
Leetcode Solutions
Bit Masking and Prefix Sum
Initialize a mask variable to 0 and an array firstOccurrence with size 32 (2^5 for each vowel parity combination) filled with -1, except firstOccurrence[0] which is set to 0.
Iterate through the string, updating the mask based on the current character.
If the character is a vowel, flip the corresponding bit in the mask.
If firstOccurrence[mask] is -1, set it to the current index + 1.
Calculate the length of the current valid substring as the difference between the current index and firstOccurrence[mask].
Update the result with the maximum length found so far.