All problems
0974MediumArrayStringPrefix Sum

Vowel-Bounded Labels in Each Stretch

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2559Count Vowel Strings in Ranges

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def vowel_strings(words: list[str], queries: list[list[int]]) -> list[int]:
Java
public int[] vowelStrings(String[] words, int[][] queries)
September 7
Apply