human
Minimum number of operations to move all uppercase characters before all lower case characters | Function to return the minimum number of operations required.
To store the indices of the last uppercase and the first lowercase character.
Find the last uppercase character.
Find the first lowercase character.
If all the characters are either uppercase or lowercase.
Count of uppercase characters that appear after the first lowercase character.
Count of lowercase characters that appear before the last uppercase character.
Return the minimum operations required.
Driver Code"
Solution in Python:
assistant
#Here is code to minimum number of operations to move all uppercase characters before all lower case characters and the other steps required.
 def minOperations ( str , n ) :
	lastUpper = - 1
	firstLower = - 1
	for i in range ( n - 1 , - 1 , - 1 ) :
		if ( str [ i ] . isupper ( ) ) :
			lastUpper = i
			break
	for i in range ( n ) :
		if ( str [ i ] . islower ( ) ) :
			firstLower = i
			break
	if ( lastUpper == - 1 or firstLower == - 1 ) :
		return 0
	countUpper = 0
	for i in range ( firstLower , n ) :
		if ( str [ i ] . isupper ( ) ) :
			countUpper += 1
	countLower = 0
	for i in range ( lastUpper ) :
		if ( str [ i ] . islower ( ) ) :
			countLower += 1
	return min ( countLower , countUpper )
if __name__ == " _ _ main _ _ " :
	str = " geEksFOrGEekS "
	n = len ( str )
	print ( minOperations ( str , n ) )