Count of rotations required to generate a sorted array | Function to return the count of rotations ; Find the smallest element ; Return its index ; If array is not rotated at all ; Driver Code
def countRotation ( arr , n ) : NEW_LINE INDENT for i in range ( 1 , n ) : NEW_LINE INDENT if ( arr [ i ] < arr [ i - 1 ] ) : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT return 0 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr1 = [ 4 , 5 , 1 , 2 , 3 ] NEW_LINE n = len ( arr1 ) NEW_LINE print ( countRotation ( arr1 , n ) ) NEW_LINE DEDENT