Find Longest Substring With Even Vowel Counts
mediumTime: O(n)Space: O(1)
Recognize the pattern
longest substring with all vowels appearing even timesbitmask parity trackingprefix XOR
Brute force idea
Check every substring — O(n²).
Better approach
5-bit bitmask tracks vowel parity. Same bitmask at positions i,j means even counts between them. Store first occurrence. O(n).
Key invariant
Same bitmask = same parity state = vowels toggled even times between. Length = j - firstOccurrence[mask].
Watch out for
Not initializing mask 0 at position -1 — needed for substrings starting at index 0.