You are given:
words
: These are lowercase English words.queries
: Each query is a range [li, ri]
.Task:
For each query [li, ri]
, count how many words in the range (from index li
to ri
, inclusive) start and end with a vowel.
The vowels are 'a'
, 'e'
, 'i'
, 'o'
, and 'u'
.
Return an array ans
where:
ans[i]
is the answer to the i-th
query.Input: words = ["aba", "bcb", "ece", "aa", "e"],
queries = [[0, 2], [1, 4], [1, 1]]
Output: [2, 3, 0]
Words starting and ending with vowels:
"aba"
, "ece"
, "aa"
, "e"
.
[0, 2]
:"aba"
and "ece"
, so the result is 2
.[1, 4]
:"ece"
, "aa"
, "e"
, so the result is 3
.[1, 1]
:0
.Input: words = ["a","e","i"],
queries = [[0,2],[0,1],[2,2]]
Output: [2, 3, 0]
All words start and end with vowels.
[0, 2]
:"a"
, "e"
, "i"
) satisfy the condition, so the result is 3
.[0, 1]
:"a"
and "e"
, so the result is 2
.[2, 2]
:"i"
, so the result is 1
.words.length
): Up to .words[i].length
): Up to .queries.length
): Up to .Loading component...
Loading component...