prefix
of size n+1
where n
is the length of words
, with all elements set to 0.words
array, and for each word, check if it starts and ends with a vowel.prefix
array.prefix
array to contain the cumulative sum up to the current index.ans
to store the results of the queries.queries
array, and for each query [li, ri]
, calculate the number of words starting and ending with a vowel in the range by subtracting prefix[li]
from prefix[ri + 1]
.ans
list.ans
list.