human
What is a code to count substrings that contain all vowels and the other steps required given the following:
Count substrings that contain all vowels | SET 2 | Function that returns true if c is a vowel.
Function to return the count of sub - strings that contain every vowel at least once and no consonant.
Map is used to store count of each vowel.
Start index is set to 0 initially.
If substring till now have all vowels atleast once increment start index until there are all vowels present between ( start , i ) and add n - i each time.
Function to extract all maximum length sub - strings in s that contain only vowels and then calls the countSubstringsUtil ( ) to find the count of valid sub - strings in that string.
If current character is a vowel then append it to the temp string.
The sub - string containing all vowels ends here.
If there was a valid sub - string.
Reset temp string.
For the last valid sub - string.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count substrings that contain all vowels and the other steps required.
 def isVowel ( c ) :
	return ( c == ' a ' or c == ' e ' or c == ' i ' or c == ' o ' or c == ' u ' ) ;
def countSubstringsUtil ( s ) :
	count = 0 ;
	mp = dict . fromkeys ( s , 0 ) ;
	n = len ( s ) ;
	start = 0 ;
	for i in range ( n ) :
		mp [ s [ i ] ] += 1 ;
		while ( mp [ ' a ' ] > 0 and mp [ ' e ' ] > 0 and mp [ ' i ' ] > 0 and mp [ ' o ' ] > 0 and mp [ ' u ' ] > 0 ) :
			count += n - i ;
			mp [ s [ start ] ] -= 1 ;
			start += 1 ;
	return count ;
def countSubstrings ( s ) :
	count = 0 ;
	temp = " " ;
	for i in range ( len ( s ) ) :
		if ( isVowel ( s [ i ] ) ) :
			temp += s [ i ] ;
		else :
			if ( len ( temp ) > 0 ) :
				count += countSubstringsUtil ( temp ) ;
			temp = " " ;
	if ( len ( temp ) > 0 ) :
		count += countSubstringsUtil ( temp ) ;
	return count ;
if __name__ == " _ _ main _ _ " :
	s = " aeouisddaaeeiouua " ;
	print ( countSubstrings ( s ) ) ;