text: Lexicographically smallest K | Function that prints the lexicographically smallest K - length substring containing maximum number of vowels ; St || e the length of the string ; Initialize a prefix sum array ; Loop through the string to create the prefix sum array ; St || e 1 at the index if it is a vowel ; Otherwise , st || e 0 ; Process the prefix array ; Initialize the variable to st || e maximum count of vowels ; Initialize the variable to st || e substring with maximum count of vowels ; Loop through the prefix array ; St || e the current count of vowels ; Update the result if current count is greater than maximum count ; Update lexicographically smallest substring if the current count is equal to the maximum count ; Return the result ; Driver Program
code: function maxVowelSubString ( str , K ) { var N = str . length ; var pref = Array ( N ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ' str [ i ] == ' ' str [ i ] == ' ' str [ i ] == ' ' str [ i ] == ' ' ) pref [ i ] = 1 ; else pref [ i ] = 0 ; if ( i ) pref [ i ] += pref [ i - 1 ] ; } var maxCount = pref [ K - 1 ] ; var res = str . substring ( 0 , K ) ; for ( var i = K ; i < N ; i ++ ) { var currCount = pref [ i ] - pref [ i - K ] ; if ( currCount > maxCount ) { maxCount = currCount ; res = str . substring ( i - K + 1 , i - 1 ) ; } else if ( currCount == maxCount ) { var temp = str . substring ( i - K + 1 , i + 1 ) ; if ( temp < res ) res = temp ; } } return res ; } var str = " " ; var K = 3 ; document . write ( maxVowelSubString ( str , K ) ) ;