human
Write me a code to minimum adjacent swaps to move maximum and minimum to corners and the other steps required given the following:
Minimum adjacent swaps to move maximum and minimum to corners | Function that returns the minimum swaps.
Index of leftmost largest element.
Index of rightmost smallest element.
Driver code"
Solution in Python:
assistant
#Here is code to minimum adjacent swaps to move maximum and minimum to corners and the other steps required.
 def minSwaps ( arr ) :
	n = len ( arr )
	maxx , minn , l , r = - 1 , arr [ 0 ] , 0 , 0
	for i in range ( n ) :
		if arr [ i ] > maxx :
			maxx = arr [ i ]
			l = i
		if arr [ i ] <= minn :
			minn = arr [ i ]
			r = i
	if r < l :
		print ( l + ( n - r - 2 ) )
	else :
		print ( l + ( n - r - 1 ) )
arr = [ 5 , 6 , 1 , 3 ]
minSwaps ( arr )