human
Give me a code to length of the smallest substring which contains all vowels and the other steps required given the following:
Length of the smallest substring which contains all vowels | Function to return the index for respective vowels to increase their count.
Returns - 1 for consonants.
Function to find the minimum length.
Store the starting index of the current substring.
Store the frequencies of vowels.
If the current character is a vowel.
Increase its count.
Move start as much right as possible.
Condition for valid substring.
Driver code"
Solution in Python:
assistant
#Here is code to length of the smallest substring which contains all vowels and the other steps required.
 def get_index ( ch ) :
	if ( ch == ' a ' ) :
		return 0
	elif ( ch == ' e ' ) :
		return 1
	elif ( ch == ' i ' ) :
		return 2
	elif ( ch == ' o ' ) :
		return 3
	elif ( ch == ' u ' ) :
		return 4
	else :
		return - 1
def findMinLength ( s ) :
	n = len ( s )
	ans = n + 1
	start = 0
	count = [ 0 ] * 5
	for x in range ( n ) :
		idx = get_index ( s [ x ] )
		if ( idx != - 1 ) :
			count [ idx ] += 1
		idx_start = get_index ( s [ start ] )
		while ( idx_start == - 1 or count [ idx_start ] > 1 ) :
			if ( idx_start != - 1 ) :
				count [ idx_start ] -= 1
			start += 1
			if ( start < n ) :
				idx_start = get_index ( s [ start ] )
		if ( count [ 0 ] > 0 and count [ 1 ] > 0 and count [ 2 ] > 0 and count [ 3 ] > 0 and count [ 4 ] > 0 ) :
			ans = min ( ans , x - start + 1 )
	if ( ans == n + 1 ) :
		return - 1
	return ans
if __name__ == " _ _ main _ _ " :
	s = " aaeebbeaccaaoiuooooooooiuu "
	print ( findMinLength ( s ) )