3824. Minimum K to Reduce Array Within Limit Medium
1/**
2 * [3824] Minimum K to Reduce Array Within Limit
3 *
4 * You are given a positive integer array nums.
5 * For a positive integer k, define nonPositive(nums, k) as the minimum number of operations needed to make every element of nums non-positive. In one operation, you can choose an index i and reduce nums[i] by k.
6 * Return an integer denoting the minimum value of k such that nonPositive(nums, k) <= k^2.
7 *
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [3,7,5]</span>
11 * Output: <span class="example-io">3</span>
12 * Explanation:
13 * When k = 3, nonPositive(nums, k) = 6 <= k^2.
14 *
15 * Reduce nums[0] = 3 one time. nums[0] becomes 3 - 3 = 0.
16 * Reduce nums[1] = 7 three times. nums[1] becomes 7 - 3 - 3 - 3 = -2.
17 * Reduce nums[2] = 5 two times. nums[2] becomes 5 - 3 - 3 = -1.
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">nums = [1]</span>
22 * Output: <span class="example-io">1</span>
23 * Explanation:
24 * When k = 1, nonPositive(nums, k) = 1 <= k^2.
25 *
26 * Reduce nums[0] = 1 one time. nums[0] becomes 1 - 1 = 0.
27 * </div>
28 *
29 * Constraints:
30 *
31 * 1 <= nums.length <= 10^5
32 * 1 <= nums[i] <= 10^5
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/minimum-k-to-reduce-array-within-limit/
38// discuss: https://leetcode.com/problems/minimum-k-to-reduce-array-within-limit/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn minimum_k(nums: Vec<i32>) -> i32 {
44 0
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_3824() {
56 }
57}
58Back
© 2026 bowen.ge All Rights Reserved.