human
Give me a code to count rotations required to sort given array in non and the other steps required given the following:
Count rotations required to sort given array in non | Function to count minimum anti - clockwise rotations required to sort the array in non - increasing order.
Stores count of arr [ i + 1 ] > arr [ i ].
Store last index of arr [ i + 1 ] > arr [ i ].
Traverse the given array.
If the adjacent elements are in increasing order.
Increment count.
Update index.
Prthe result according to the following conditions.
Otherwise , it is not possible to sort the array.
Given array.
Function Call"
Solution in Python:
assistant
#Here is code to count rotations required to sort given array in non and the other steps required.
 def minMovesToSort ( arr , N ) :
	count = 0
	index = 0
	for i in range ( N - 1 ) :
		if ( arr [ i ] < arr [ i + 1 ] ) :
			count += 1
			index = i
	if ( count == 0 ) :
		print ( "0" )
	elif ( count == N - 1 ) :
		print ( N - 1 )
	elif ( count == 1 and arr [ 0 ] <= arr [ N - 1 ] ) :
		print ( index + 1 )
	else :
		print ( " - 1" )
arr = [ 2 , 1 , 5 , 4 , 2 ]
N = len ( arr )
minMovesToSort ( arr , N )