Company: Ion Group_24july
Difficulty: medium
Minimum Operations to Sort Array Problem Description Write a function that finds the fewest operations needed to bring an array arr of size n into non-decreasing order, where each operation (applied zero or more times) works like this: Take the array's first element out and place it at the very end. Then keep swapping that relocated element with the one before it until it lands at the front of the array or hits a neighbor that is strictly smaller. The function minOperationsToSort will take the following input: int arr[n] : The elements of the array arr . It should return the smallest number of such operations that puts arr into non-decreasing order, or -1 when no sequence of operations can achieve that. Examples Example 1: Input: arr = [5, 3, 1] Operations on the array: Array before the operation | Array after the operation ---------------------------|-------------------------- [5, 3, 1] | [3, 1, 5] [3, 1, 5] | [1, 3, 5] Output: 2 Explanation: Two applications of the operation bring ar