3065. Minimum Operations to Exceed Threshold Value I Easy
1/**
2 * [3065] Minimum Operations to Exceed Threshold Value I
3 *
4 * You are given a 0-indexed integer array nums, and an integer k.
5 * In one operation, you can remove one occurrence of the smallest element of nums.
6 * Return the minimum number of operations needed so that all elements of the array are greater than or equal to k.
7 *
8 * <strong class="example">Example 1:
9 *
10 * Input: nums = [2,11,10,1,3], k = 10
11 * Output: 3
12 * Explanation: After one operation, nums becomes equal to [2, 11, 10, 3].
13 * After two operations, nums becomes equal to [11, 10, 3].
14 * After three operations, nums becomes equal to [11, 10].
15 * At this stage, all the elements of nums are greater than or equal to 10 so we can stop.
16 * It can be shown that 3 is the minimum number of operations needed so that all elements of the array are greater than or equal to 10.
17 *
18 * <strong class="example">Example 2:
19 *
20 * Input: nums = [1,1,2,4,9], k = 1
21 * Output: 0
22 * Explanation: All elements of the array are greater than or equal to 1 so we do not need to apply any operations on nums.
23 * <strong class="example">Example 3:
24 *
25 * Input: nums = [1,1,2,4,9], k = 9
26 * Output: 4
27 * Explanation: only a single element of nums is greater than or equal to 9 so we need to apply the operations 4 times on nums.
28 *
29 *
30 * Constraints:
31 *
32 * 1 <= nums.length <= 50
33 * 1 <= nums[i] <= 10^9
34 * 1 <= k <= 10^9
35 * The input is generated such that there is at least one index i such that nums[i] >= k.
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i/
41// discuss: https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn min_operations(nums: Vec<i32>, k: i32) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_3065() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.