human
Minimize cost to replace all the vowels of a given String by a single vowel | Function that return true if the given character is a vowel.
Function to return the minimum cost to convert all the vowels of a string to a single one.
Stores count of respective vowels.
Iterate through the string.
If a vowel is encountered.
Calculate the cost.
Return the minimum cost.
Driver code"
Solution in Python:
assistant
#Here is code to minimize cost to replace all the vowels of a given String by a single vowel and the other steps required.
 def isVowel ( ch ) :
	if ( ch == ' a ' or ch == ' e ' or ch == ' i ' or ch == ' o ' or ch == ' u ' ) :
		return True ;
	else :
		return False ;
def minCost ( S ) :
	cA = 0 ;
	cE = 0 ;
	cI = 0 ;
	cO = 0 ;
	cU = 0 ;
	for i in range ( len ( S ) ) :
		if ( isVowel ( S [ i ] ) ) :
			cA += abs ( ord ( S [ i ] ) - ord ( ' a ' ) ) ;
			cE += abs ( ord ( S [ i ] ) - ord ( ' e ' ) ) ;
			cI += abs ( ord ( S [ i ] ) - ord ( ' i ' ) ) ;
			cO += abs ( ord ( S [ i ] ) - ord ( ' o ' ) ) ;
			cU += abs ( ord ( S [ i ] ) - ord ( ' u ' ) ) ;
	return min ( min ( min ( min ( cA , cE ) , cI ) , cO ) , cU ) ;
S = " geeksforgeeks " ;
print ( minCost ( S ) )