Minimum Operations to Exceed Threshold Value I - Problem
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.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [2,11,10,1,3], k = 10
›
Output:
3
💡 Note:
Elements less than 10 are [2,1,3]. We need to remove all 3 of them, so answer is 3.
Example 2 — All Elements Valid
$
Input:
nums = [1,1,2,4,9], k = 1
›
Output:
0
💡 Note:
All elements are already ≥ 1, so no operations needed.
Example 3 — Remove All Elements
$
Input:
nums = [2,4,6,8], k = 10
›
Output:
4
💡 Note:
All elements are less than 10, so we need to remove all 4 elements.
Constraints
- 1 ≤ nums.length ≤ 50
- 1 ≤ nums[i] ≤ 109
- 1 ≤ k ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array [2,11,10,1,3] with threshold k=10
2
Identify
Find elements < k: [2,1,3]
3
Count
3 operations needed
Key Takeaway
🎯 Key Insight: Count elements below threshold - that's exactly how many operations we need
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code