JuniorArray
Minimum Operations to Exceed Threshold Value I
You are given a 0-indexed integer array nums, and an integer k.
In one operation, you can remove one occurrence of the smallest element of nums.
Return the minimum number of operations needed so that all elements of the array are greater than or equal to k.
Example 1
Input
nums = [2,11,10,1,3], k = 10Output
3After removing the smallest element three times, the remaining elements are all greater than or equal to 10, and 3 is the minimum number of operations needed.
Example 2
Input
nums = [1,1,2,4,9], k = 1Output
0All elements of the array are greater than or equal to 1, so no operations are needed.
Constraints
- 1 <= nums.length <= 50
- 1 <= nums[i] <= 10^9
- 1 <= k <= 10^9
- The input is generated such that there is at least one index i such that nums[i] >= k.