Queries to find the count of vowels in the substrings of the given string | Javascript implementation of the approach ; Function that returns true if ch is a vowel ; Function to return the count of vowels in the substring str [ l ... r ] ; To store the count of vowels ; For every character in the index range [ l , r ] ; If the current character is a vowel ; For every query ; Find the count of vowels for the current query ; Driver code
let N = 2 ; function isVowel ( ch ) { return ( ch == ' ' ch == ' ' ch == ' ' ch == ' ' ch == ' ' ) ; } function countVowels ( str , l , r ) { let cnt = 0 ; for ( let i = l ; i <= r ; i ++ ) { if ( isVowel ( str [ i ] ) ) cnt ++ ; } return cnt ; } function performQueries ( str , queries , q ) { for ( let i = 0 ; i < q ; i ++ ) { document . write ( countVowels ( str , queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) + " " ) ; } } let str = " " ; let queries = [ [ 1 , 3 ] , [ 2 , 4 ] , [ 1 , 9 ] ] ; let q = queries . length ; performQueries ( str , queries , q ) ;