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
Inputnums = [2,11,10,1,3], k = 10
Output3
After 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
Inputnums = [1,1,2,4,9], k = 1
Output0
All 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.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate