Has Vowels
Updated
Problem statement
Given a string array that contains n elements, each composed of lowercase English letters, and q queries, each query of the format i-r, for each query, determine how many strings starting from index i and ending at index r have vowels as the first and last character. Vowels are in {a,e,i,o,u}.
Function
hasVowels(strArr: String[], queries: String[]) → int[]
Complete the function hasVowels in the editor below. It must return an array of integers that represent the result of each query in the order given.
hasVowels has the following parameters:
strArr string[]: an array ofnstringsquery string[]: an array ofqstrings, each of which describes an intervali-rusing integers delimited by a dash
Examples
Example 1
strArr = ["aba","bcb","ece","aa","e"]queries = ["1-3","2-5","2-2"]return = [2, 3, 0]
These strings represent two dash delimited integers i and r, the start and end indices of the interval, inclusive. Using 1-based indexing in the string array, the interval 1-3 contains two strings that start and end with a vowel: 'aba' and 'ece'. The interval 2-5 also has three. The third interval, from 2-2, the only element in the interval, 'bcb' does not begin and end with a vowel. The return array for the queries is [2, 3, 0].
Constraints
1 ≤ n, q ≤ 10^51 ≤ i ≤ r ≤ n1 ≤ size of strArr[i] ≤ 10
More MathWorks interview questions
- Earliest Time to Schedule a MeetingOA · Seen Nov 2026
- Minimum Cost to Serve Requests on a RingOA · Seen Nov 2026
- Minimum Tree Diameter After Removing K LeavesOA · Seen Nov 2026
- Cities on Shortest Delivery RoutesOA · Seen Nov 2026
- Repeated Mirror XOROA · Seen Nov 2026
- Beautiful ArrangementONSITE INTERVIEW · Seen Jul 2026
- Find Minimum Cost to Remove Array ElementsONSITE INTERVIEW · Seen Jul 2026
- Group Shifted StringsONSITE INTERVIEW · Seen Jul 2026
- Longest Valid ParenthesesONSITE INTERVIEW · Seen Jul 2026
- Balancing TeamsOA · Seen Nov 2025
Similar questions at other companies
- Fill One Exact-Length Binary WindowAmazon · OA
- Maximum Number of Workers with Equal Left and Right ShoesTesla · OATesla interview questions
- Number of Divisible Substrings (For MLE)Wayfair · OAWayfair interview questions
- Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
- Longest Repeated Letter Block with Adjacent SwapsIntuit · OAIntuit interview questions
- Earliest Time to Schedule a MeetingMicrosoft · OAMicrosoft interview questions
- Maximum Equalized Substrings After One Adjacent SwapVisa · OAVisa interview questions
- Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions
- Balanced Split String with WildcardsTwo Sigma · OATwo Sigma interview questions
- Longest Balanced Substring After One SwapTekion · OATekion interview questions