Minimum Array Length After Pair Removals
Given an integer array nums sorted in non-decreasing order.
You can perform the following operation any number of times:
- Choose two indices,
iandj, wherenums[i] < nums[j]. - Then, remove the elements at indices
iandjfromnums. The remaining elements retain their original order, and the array is re-indexed.
Return the minimum length of nums after applying the operation zero or more times.
Example 1
Input
nums = [1,2,3,4]Output
0All elements can be removed by repeatedly pairing a smaller number with a larger number.
Example 2
Input
nums = [1,1,2,2,3,3]Output
0All elements can be removed by pairing each smaller occurrence with a larger occurrence.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^9
- nums is sorted in non-decreasing order.