#2559
Count Vowel Strings in Ranges
pupil · 595 · lc medium +29 · verified · 67.8% accepted · 1,175 likes · top 74%
Description
Given a 0-indexed string array words and range queries where each queries[i] = [li, ri], count how many strings in the subrange words[li..ri] both start and end with a vowel ('a', 'e', 'i', 'o', 'u'). Return an array with one answer per query.
Example 1:
Input: words = ["aba","bcb","ece","aa","e"], queries = [[0,2],[1,4],[1,1]]
Output: [2,3,0]
Explanation: The strings starting and ending with a vowel are "aba", "ece", "aa" and "e".
The answer to the query [0,2] is 2 (strings "aba" and "ece").
to query [1,4] is 3 (strings "ece", "aa", "e").
to query [1,1] is 0.
We return [2,3,0].
Example 2:
Input: words = ["a","e","i"], queries = [[0,2],[0,1],[2,2]]
Output: [3,2,1]
Explanation: Every string satisfies the conditions, so we return [3,2,1].
Code
1
2
3