Given an array nums, you can perform the following operation any number of times:
Return the minimum number of operations needed to make the array non-decreasing.
An array is said to be non-decreasing if each element is greater than or equal to its previous element (if it exists).
Examples
Example 1
Input: nums = [5,2,3,1]
Output: 2
Explanation:
The array nums became non-decreasing in two operations.
Example 2
Input: nums = [1,2,2]
Output: 0
Explanation:
The array nums is already sorted.
Constraints
1 <= nums.length <= 105
-109 <= nums[i] <= 109
3510. Minimum Pair Removal to Sort Array II
Hard
50 Points
Array
Hash Table
Linked List
Heap (Priority Queue)
Simulation
Doubly-Linked List
Ordered Set
Given an array nums, you can perform the following operation any number of times:
Return the minimum number of operations needed to make the array non-decreasing.
An array is said to be non-decreasing if each element is greater than or equal to its previous element (if it exists).
Examples
Example 1
Input: nums = [5,2,3,1]
Output: 2
Explanation:
The array nums became non-decreasing in two operations.
Example 2
Input: nums = [1,2,2]
Output: 0
Explanation:
The array nums is already sorted.
Constraints
1 <= nums.length <= 105
-109 <= nums[i] <= 109
Minimum Pair Removal to Sort Array II - Practice Coding | SlaveCode