human
Lexicographically smallest K | Function that prints the lexicographically smallest K - length substring containing maximum number of vowels.
Store the length of the string.
Initialize a prefix sum array.
Loop through the string to create the prefix sum array.
Store 1 at the index if it is a vowel.
Otherwise , store 0.
Process the prefix array.
Initialize the variable to store maximum count of vowels.
Initialize the variable to store substring with maximum count of vowels.
Loop through the prefix array.
Store 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 code"
How can the above be solved in Python?
assistant
#Here is code to lexicographically smallest K and the other steps required.
 def maxVowelSubString ( str1 , K ) :
	N = len ( str1 )
	pref = [ 0 for i in range ( N ) ]
	for i in range ( N ) :
		if ( str1 [ i ] == ' a ' or str1 [ i ] == ' e ' or str1 [ i ] == ' i ' or str1 [ i ] == ' o ' or str1 [ i ] == ' u ' ) :
			pref [ i ] = 1
		else :
			pref [ i ] = 0
		if ( i ) :
			pref [ i ] += pref [ i - 1 ]
	maxCount = pref [ K - 1 ]
	res = str1 [ 0 : K ]
	for i in range ( K , N ) :
		currCount = pref [ i ] - pref [ i - K ]
		if ( currCount > maxCount ) :
			maxCount = currCount
			res = str1 [ i - K + 1 : i + 1 ]
		elif ( currCount == maxCount ) :
			temp = str1 [ i - K + 1 : i + 1 ]
			if ( temp < res ) :
				res = temp
	return res
if __name__ == ' _ _ main _ _ ' :
	str1 = " ceebbaceeffo "
	K = 3
	print ( maxVowelSubString ( str1 , K ) )