arr[0], arr[1], ..., arr[n-1] to arr[1], arr[2], ..., arr[n-1], arr[0].Formally, given a permutation arr of size n, determine the minimum number of operations needed to sort the given permutation in increasing order. The permutation provided is guaranteed to be sorted using only these two operations.
Note: A permutation of length n is a sequence of integers from 1 to n containing each number exactly once.
int getMinimumOperations(int[] arr)
Return the minimum number of operations required to sort arr in increasing order.
Call: getMinimumOperations([2, 3, 4, 5, 6, 7, 8, 9, 10, 1])
Output: 3
Explanation of Optimal Operations:
[1, 10, 9, 8, 7, 6, 5, 4, 3, 2][10, 9, 8, 7, 6, 5, 4, 3, 2, 1][1, 2, 3, 4, 5, 6, 7, 8, 9, 10]It can be shown that the given permutation can only be sorted using a minimum of 3 operations.
Call: getMinimumOperations([1, 2, 3, 4])
Output: 0
Explanation: The permutation is already sorted.
Call: getMinimumOperations([2, 1])
Output: 1
Explanation: Reverse the permutation once to get [1, 2].