Skip to content

Commit 9ad7f5f

Browse files
committed
Add solution #2233
1 parent 23e5ba7 commit 9ad7f5f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,7 @@
20262026
2229|[Check if an Array Is Consecutive](./solutions/2229-check-if-an-array-is-consecutive.js)|Easy|
20272027
2231|[Largest Number After Digit Swaps by Parity](./solutions/2231-largest-number-after-digit-swaps-by-parity.js)|Easy|
20282028
2232|[Minimize Result by Adding Parentheses to Expression](./solutions/2232-minimize-result-by-adding-parentheses-to-expression.js)|Medium|
2029+
2233|[Maximum Product After K Increments](./solutions/2233-maximum-product-after-k-increments.js)|Medium|
20292030
2234|[Maximum Total Beauty of the Gardens](./solutions/2234-maximum-total-beauty-of-the-gardens.js)|Hard|
20302031
2235|[Add Two Integers](./solutions/2235-add-two-integers.js)|Easy|
20312032
2236|[Root Equals Sum of Children](./solutions/2236-root-equals-sum-of-children.js)|Easy|
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* 2233. Maximum Product After K Increments
3+
* https://leetcode.com/problems/maximum-product-after-k-increments/
4+
* Difficulty: Medium
5+
*
6+
* You are given an array of non-negative integers nums and an integer k. In one operation,
7+
* you may choose any element from nums and increment it by 1.
8+
*
9+
* Return the maximum product of nums after at most k operations. Since the answer may be
10+
* very large, return it modulo 109 + 7. Note that you should maximize the product before
11+
* taking the modulo.
12+
*/
13+
14+
/**
15+
* @param {number[]} nums
16+
* @param {number} k
17+
* @return {number}
18+
*/
19+
var maximumProduct = function(nums, k) {
20+
const MOD = 1e9 + 7;
21+
const minHeap = new PriorityQueue((a, b) => a - b);
22+
23+
for (const num of nums) {
24+
minHeap.enqueue(num);
25+
}
26+
27+
for (let i = 0; i < k; i++) {
28+
const smallest = minHeap.dequeue();
29+
minHeap.enqueue(smallest + 1);
30+
}
31+
32+
let result = 1;
33+
while (!minHeap.isEmpty()) {
34+
result = (result * minHeap.dequeue()) % MOD;
35+
}
36+
37+
return result;
38+
};

0 commit comments

Comments
 (0)