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 ; pre [ i ] will store the count of vowels in the substring str [ 0. . . i ] ; Fill the pre [ ] array ; If current character is a vowel ; If its a consonant ; For every query ; Find the count of vowels for the current query ; Driver code
var N = 2 ; function isVowel ( ch ) { return ( ch == ' ' ch == ' ' ch == ' ' ch == ' ' ch == ' ' ) ; } function performQueries ( str , len , queries , q ) { var pre = Array ( len ) ; if ( isVowel ( str [ 0 ] ) ) pre [ 0 ] = 1 ; else pre [ 0 ] = 0 ; for ( var i = 1 ; i < len ; i ++ ) { if ( isVowel ( str [ i ] ) ) pre [ i ] = 1 + pre [ i - 1 ] ; else pre [ i ] = pre [ i - 1 ] ; } for ( var i = 0 ; i < q ; i ++ ) { if ( queries [ i ] [ 0 ] == 0 ) { document . write ( pre [ queries [ i ] [ 1 ] ] + " " ) ; } else { document . write ( pre [ queries [ i ] [ 1 ] ] - pre [ queries [ i ] [ 0 ] - 1 ] + " " ) ; } } } var str = " " ; var len = str . length ; var queries = [ [ 1 , 3 ] , [ 2 , 4 ] , [ 1 , 9 ] ] ; var q = queries . length performQueries ( str , len , queries , q ) ;