Maximum Number of Vowels in a Substring of Given Length
mediumTime: O(n)Space: O(1)
Signals to notice
max vowels in any substring of length kfixed-size windowcount vowels entering/leaving
Brute force first
For each window count vowels — O(nk).
The key insight
Sliding window: maintain vowel count. +1 if entering char is vowel, -1 if leaving char is vowel. Track max. O(n).
What must stay true
Vowel count updates in O(1) per slide. Never recount the whole window.
Easy way to go wrong
Recounting each window — update incrementally.