Maximum Product After K Increments

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.

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.

Example 1
Inputnums = [0,4], k = 5
Output20
Incrementing the first number 5 times gives nums = [5, 4], whose product is 20, the maximum possible product.
Example 2
Inputnums = [6,3,3,2], k = 2
Output216
Incrementing the second number once and the fourth number once gives nums = [6, 4, 3, 3], whose product is 216, the maximum possible product.

Constraints

  • 1 <= nums.length, k <= 10^5
  • 0 <= nums[i] <= 10^6

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate