Count Vowel Strings in Ranges

You are given a 0-indexed array of strings words and a 2D array of integers queries.

Each query queries[i] = [li, ri] asks us to find the number of strings present at the indices ranging from li to ri (both inclusive) of words that start and end with a vowel.

Return an array ans of size queries.length, where ans[i] is the answer to the ith query.

Note that the vowel letters are 'a', 'e', 'i', 'o', and 'u'.

Example 1
Inputwords = ["aba","bcb","ece","aa","e"], queries = [[0,2],[1,4],[1,1]]
Output[2,3,0]
The strings starting and ending with a vowel are "aba", "ece", "aa", and "e", giving counts 2, 3, and 0 for the three queries.
Example 2
Inputwords = ["a","e","i"], queries = [[0,2],[0,1],[2,2]]
Output[3,2,1]
Every string satisfies the conditions, so each query returns the size of its range.

Constraints

  • 1 <= words.length <= 10^5
  • 1 <= words[i].length <= 40
  • words[i] consists only of lowercase English letters.
  • sum(words[i].length) <= 3 * 10^5
  • 1 <= queries.length <= 10^5
  • 0 <= li <= ri < words.length

Asked at 9 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate