Class Solution
java.lang.Object
g2201_2300.s2233_maximum_product_after_k_increments.Solution
2233 - Maximum Product After K Increments.<p>Medium</p>
<p>You are given an array of non-negative integers <code>nums</code> and an integer <code>k</code>. In one operation, you may choose <strong>any</strong> element from <code>nums</code> and <strong>increment</strong> it by <code>1</code>.</p>
<p>Return <em>the <strong>maximum</strong> <strong>product</strong> of</em> <code>nums</code> <em>after <strong>at most</strong></em> <code>k</code> <em>operations.</em> Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>. Note that you should maximize the product before taking the modulo.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [0,4], k = 5</p>
<p><strong>Output:</strong> 20</p>
<p><strong>Explanation:</strong> Increment the first number 5 times.</p>
<p>Now nums = [5, 4], with a product of 5 * 4 = 20.</p>
<p>It can be shown that 20 is maximum product possible, so we return 20.</p>
<p>Note that there may be other ways to increment nums to have the maximum product.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [6,3,3,2], k = 2</p>
<p><strong>Output:</strong> 216</p>
<p><strong>Explanation:</strong> Increment the second number 1 time and increment the fourth number 1 time.</p>
<p>Now nums = [6, 4, 3, 3], with a product of 6 * 4 * 3 * 3 = 216.</p>
<p>It can be shown that 216 is maximum product possible, so we return 216.</p>
<p>Note that there may be other ways to increment nums to have the maximum product.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length, k <= 10<sup>5</sup></code></li>
<li><code>0 <= nums[i] <= 10<sup>6</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maximumProduct
public int maximumProduct(int[] nums, int k)
-