2233. Maximum Product After K Increments Medium

@problem@discussion
#Array#Greedy#Heap (Priority Queue)



1/**
2 * [2233] Maximum Product After K Increments
3 *
4 * You are given an array of non-negative integers nums and an integer k. In one operation, you may choose any element from nums and increment it by 1.
5 * Return the maximum product of nums after at most k operations. Since the answer may be very large, return it modulo 10^9 + 7. Note that you should maximize the product before taking the modulo. 
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [0,4], k = 5
10 * Output: 20
11 * Explanation: Increment the first number 5 times.
12 * Now nums = [5, 4], with a product of 5 * 4 = 20.
13 * It can be shown that 20 is maximum product possible, so we return 20.
14 * Note that there may be other ways to increment nums to have the maximum product.
15 * 
16 * Example 2:
17 * 
18 * Input: nums = [6,3,3,2], k = 2
19 * Output: 216
20 * Explanation: Increment the second number 1 time and increment the fourth number 1 time.
21 * Now nums = [6, 4, 3, 3], with a product of 6 * 4 * 3 * 3 = 216.
22 * It can be shown that 216 is maximum product possible, so we return 216.
23 * Note that there may be other ways to increment nums to have the maximum product.
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= nums.length, k <= 10^5
29 * 	0 <= nums[i] <= 10^6
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/maximum-product-after-k-increments/
35// discuss: https://leetcode.com/problems/maximum-product-after-k-increments/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn maximum_product(nums: Vec<i32>, k: i32) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_2233() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.