A ranger station labels every checkpoint along a trail with a lowercase codename. For a safety audit, the station only cares about one contiguous stretch of the checkpoint list, identified by two indices, and wants to know how many codenames in that stretch both begin and end with a vowel ('a', 'e', 'i', 'o', 'u') -- a pattern the rangers use to flag checkpoints near a water source.
Given the full list of codenames and the stretch's boundary indices (inclusive, 0-indexed), count how many codenames in that stretch satisfy the vowel-bracket pattern. A codename of length 1 satisfies the pattern exactly when its single letter is a vowel.
A single integer: the number of codenames among codenames[left..right] whose first and last letters are both vowels.
Example 1
Input
4 area book ultra look 0 2
Expected
2
Explanation
The audited stretch covers codenames[0..2] = "area", "book", "ultra". "area" starts and ends with 'a' (both vowels), "book" starts with 'b' (not a vowel, excluded), and "ultra" starts with 'u' and ends with 'a' (both vowels). Two codenames satisfy the pattern, so the answer is 2.
Example 2
Input
1 e 0 0
Expected
1
Explanation
There is only one checkpoint, "e", and the audited stretch is just that single codename. Its only letter, 'e', is a vowel, so it counts as both starting and ending with a vowel. The answer is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →