Count Vowel Substrings of a String
Real-world version: All-Five Vowel WindowsThe statement here is our own: the same inputs, outputs and technique.
A speech-training tool scans a lowercase transcription text for stretches that drill all five vowel sounds.
A vowel window is a non-empty contiguous stretch of text that contains no consonant and in which each of a, e, i, o and u appears at least once. Two windows count separately when they begin or end at different positions, even if they spell the same thing.
Return the number of vowel windows in text.
Examples
Example 1
- Input
- text = "aeioua"
- Output
- 3
The windows are "aeiou" starting at 0, "aeioua" starting at 0 and "eioua" starting at 1.
Example 2
- Input
- text = "oiuae"
- Output
- 1
The whole transcription is the only window; every shorter stretch is missing a vowel.
Example 3
- Input
- text = "aeiouzaeiou"
- Output
- 2
The five characters before the z form one window and the five after it form another; no window can span the z.
Example 4
- Input
- text = "banana"
- Output
- 0
No stretch of this transcription contains all five vowels.
Constraints
- 1 <= text.length <= 100
- text consists of lowercase English letters only.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def count_vowel_substrings(text: str) -> int:public int countVowelSubstrings(String text)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 4 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's