My first instinct was to reach for a frequency map and just slide a window, which is the right skeleton, but I kept fumbling the part where a consonant resets everything.
First, clarify the problem and edge cases, then propose a sliding window approach that maintains a count of each vowel in the current window. Expand the right pointer to include characters, and when the window contains all five vowels, count all valid substrings ending at the right pointer by moving the left pointer while the window remains valid. Finally, analyze time and space complexity to show O(n) time and O(1) space.
Pro tip: Emphasize that consonants reset the window, and that counting valid substrings can be done by tracking the minimum left index for each right index, avoiding redundant checks. This demonstrates efficient handling of repeated vowels and long runs.
Restate the problem to ensure understanding: count contiguous substrings consisting only of vowels and containing all five vowels. Discuss edge cases like empty string, no vowels, or strings with consonants.
Use two pointers (left and right) to represent a window of vowels. Maintain a frequency array for the five vowels and a count of how many vowels have frequency > 0. Expand right to include new characters; if a consonant is encountered, reset the window and move left past it.
When the window contains all five vowels, all substrings starting from left to some index before the first occurrence of a vowel that would drop the count below 5 are valid. Efficiently count these by tracking the leftmost valid start for each right.
When a consonant is found, reset the frequency array and set left to right+1, effectively starting a new window. This ensures only vowel-only substrings are considered.
Show that each character is processed at most twice (once by right, once by left), giving O(n) time. Space is O(1) since the frequency array has fixed size 5.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.