Find the Longest Substring Containing Vowels in Even Counts - Problem
Given a string s, return the length of the longest substring containing each vowel ('a', 'e', 'i', 'o', 'u') an even number of times.
A substring is a contiguous sequence of characters within a string. For the substring to be valid, every vowel must appear an even number of times (including zero times).
Note: Consonants can appear any number of times and don't affect the validity of the substring.
Input & Output
Example 1 — Basic Case
$
Input:
s = "eleetminicoworoep"
›
Output:
13
💡 Note:
The substring "leetminicoworoep" contains: a:0, e:4, i:2, o:4, u:0. All vowels appear an even number of times, giving length 13.
Example 2 — No Vowels
$
Input:
s = "bcbcbc"
›
Output:
6
💡 Note:
The entire string has no vowels, so all vowels appear 0 times (even). The full length 6 is the answer.
Example 3 — All Odd Counts
$
Input:
s = "aeiou"
›
Output:
0
💡 Note:
Each vowel appears exactly once (odd count). No valid substring exists where all vowels have even counts.
Constraints
- 1 ≤ s.length ≤ 5 × 104
- s consists of lowercase English letters only
Visualization
Tap to expand
Understanding the Visualization
1
Input Analysis
String "eleetminicoworoep" with vowels to track
2
State Tracking
Track vowel count parity using bitmask
3
Result
Find longest substring with all even vowel counts
Key Takeaway
🎯 Key Insight: Use bitmask to track vowel parity - when same pattern repeats, substring between has all even vowel counts
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code