Count Vowel Strings in Ranges
Real-world version: Vowel-Bounded Labels in Each StretchThe statement here is our own: the same inputs, outputs and technique.
Labels are given as words, and each entry of queries is a pair [l, r] naming a stretch of the list, ends included.
A label is vowel-bounded when both its first and its last character are vowels, that is one of 'a', 'e', 'i', 'o' or 'u'. A label of one character counts when that character is a vowel.
Return, for each stretch in turn, how many vowel-bounded labels it holds.
Examples
Example 1
- Input
- words = ["opal", "brick", "aria", "echo", "damp"], queries = [[0, 4], [1, 3], [2, 2], [4, 4]]
- Output
- [2, 2, 1, 0]
"aria" and "echo" both begin and end with a vowel; "opal" ends in a consonant, and "brick" and "damp" begin with one. So the whole list holds two, the middle stretch holds two, and the last two stretches hold one and none.
Example 2
- Input
- words = ["ba"], queries = [[0, 0]]
- Output
- [0]
The label "ba" begins with a consonant, so it does not count even though it ends with a vowel.
Example 3
- Input
- words = ["a"], queries = [[0, 0]]
- Output
- [1]
A label of one character counts when that character is a vowel, so it is both the first and the last.
Constraints
- 1 <= words.length <= 10^5
- 1 <= words[i].length <= 40
- Every entry of words consists of lowercase English letters only
- 1 <= queries.length <= 10^5
- queries[i].length == 2
- 0 <= queries[i][0] <= queries[i][1] <= words.length - 1
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 vowel_strings(words: list[str], queries: list[list[int]]) -> list[int]:public int[] vowelStrings(String[] words, int[][] queries)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 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
More on the same topics
- Shifting Letters IIReal-world version: Rolling Letters Over StretchesMedium
- Minimum Number of Operations to Move All Balls to Each BoxReal-world version: Gathering the Crates Into Every BayMedium
- Longest Common PrefixReal-world version: Shared Crate CodeEasy
- Find Pivot IndexReal-world version: Beam Balance StationEasy