Skip to main content
Back to problems
#3065
Easy Algorithms

Minimum operations to exceed threshold value i

Array
86.6% acceptance
Feb 25, 2026
172
17
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.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn min_operations(nums: Vec<i32>, k: i32) -> i32 {
    nums.iter().filter(|&&x| x < k).count() as i32
  }
}