File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 2026
2026
2229|[ Check if an Array Is Consecutive] ( ./solutions/2229-check-if-an-array-is-consecutive.js ) |Easy|
2027
2027
2231|[ Largest Number After Digit Swaps by Parity] ( ./solutions/2231-largest-number-after-digit-swaps-by-parity.js ) |Easy|
2028
2028
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|
2029
2030
2234|[ Maximum Total Beauty of the Gardens] ( ./solutions/2234-maximum-total-beauty-of-the-gardens.js ) |Hard|
2030
2031
2235|[ Add Two Integers] ( ./solutions/2235-add-two-integers.js ) |Easy|
2031
2032
2236|[ Root Equals Sum of Children] ( ./solutions/2236-root-equals-sum-of-children.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments