Longest Substring Containing Vowels in Even Counts
Problem Statement
You are given a string s of lowercase letters.
Find the longest contiguous substring in which each vowel — a, e, i, o, u — appears an even number of times, and return its length. Zero times counts as even, so a substring with no vowels at all is fine.
A string s of lowercase English letters.
The length of the longest substring where every vowel count is even.
"leetminicowor" has e×2, i×2, o×2 and no a or u. Every count is even.
"leetc" has e×2 and no other vowels.
There are no vowels at all, so every count is 0 (even). The whole string works.
- • 1 ≤ s.length ≤ 5 · 10^5
- • s contains only lowercase English letters
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Fix each start, grow the end while tracking vowel parities, check all even
Same parity mask seen before ⇒ every vowel is even in between; store the first index of each of the 32 masks
For every start, walk the end to the right. Keep a small mask of which vowels are odd so far in s[start..end]. When the mask is 0, every vowel is even, so update the best length.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Prefix Sum translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.