Company: Ion Group_24july
Difficulty: medium
Minimum Operations to Sort Array Problem Description Implement a function that determines the minimum number of operations required to sort an array arr of size n in non-decreasing order using the following operations any number of times (possibly zero): Extract the first element of the array and insert it at the end. Then swap that element with the previous one until it becomes the first or is strictly greater than the previous one. The function minOperationsToSort will take the following input: int arr[n] : The elements of the array arr . The function should return an integer denoting the minimum number of operations needed to sort the array in non-decreasing order, or -1 if sorting is impossible. 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: The array arr can be sorted in non-decreasing