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 109 + 7. Note that you should maximize the product before taking the modulo.&nbsp;

&nbsp;
Example 1:

Input: nums = [0,4], k = 5
Output: 20
Explanation: Increment the first number 5 times.
Now nums = [5, 4], with a product of 5 * 4 = 20.
It can be shown that 20 is maximum product possible, so we return 20.
Note that there may be other ways to increment nums to have the maximum product.


Example 2:

Input: nums = [6,3,3,2], k = 2
Output: 216
Explanation: Increment the second number 1 time and increment the fourth number 1 time.
Now nums = [6, 4, 3, 3], with a product of 6 * 4 * 3 * 3 = 216.
It can be shown that 216 is maximum product possible, so we return 216.
Note that there may be other ways to increment nums to have the maximum product.


&nbsp;
Constraints:


	1 &lt;= nums.length, k &lt;= 105
	0 &lt;= nums[i] &lt;= 106


import heapq

class Solution:
    def maximumProduct(self, nums, k: int) -> int:
        
        # creating a heap
        heap = []
        for i in nums:
            heapq.heappush (heap,i)
            
            
        # basic idea here is keep on incrementing smallest number, then only multiplication of that number will be greater
        # so basically till I have operations left I will increment my smallest number
        while k :
            current = heapq.heappop(heap)
            heapq.heappush(heap, current+1)
            k-=1
            
        result =1
        
        # Just Multiply all the numbers in heap and return the value
        while len(heap)>0:
            x= heapq.heappop(heap)
            result =(result*x )% (10**9+7)
            
        return result
class Solution {
    public int maximumProduct(int[] nums, int k) {
        
        Queue<Integer> pq = new PriorityQueue<>();
        for (int num : nums)    pq.add(num);
        
        while (k-->0) {
            int top = pq.poll() + 1 ;
            pq.add(top);
        }

        long res = 1;
        while (!pq.isEmpty()) {
            res = (res*pq.poll()) % 1000000007;
        }

        return (int)(res);
    }
}
class Solution {
public:
    int maximumProduct(vector<int>& nums, int k) {

        priority_queue<int, vector<int>, greater<int>> pq(nums.begin(), nums.end());

        while(k--) {
            int mini = pq.top();
            pq.pop();
            pq.push(mini + 1);
        }

        long long ans = 1, mod = 1e9+7;

        while(!pq.empty()) {
            ans = ((ans % mod) * (pq.top() % mod)) % mod;
            pq.pop();
        }

        return (int)ans;
    }
};
var maximumProduct = function(nums, k) {
  let MOD = Math.pow(10, 9) + 7;

  // build a new minimum priority queue
  // LeetCode loads MinPriorityQueue by default, no need to implement again
  let queue = new MinPriorityQueue();
  for (let i = 0; i < nums.length; i++) {
    queue.enqueue(nums[i], nums[i]);
  }

  // To maximize the product, take the smallest element out
  // add 1 to it and add it back to the queue
  let count = 0;
  while (count < k && queue.size() > 0) {
    let {element, priority} = queue.dequeue();
    queue.enqueue(element + 1, priority + 1);
    count += 1;
  }

  // calculate the product
  let result = 1;
  let elements = queue.toArray().map((a) => a.element);
  for (let i = 0; i < elements.length; i++) {
    result = (result * elements[i]) % MOD;
  }

  return result;
};
Maximum Product After K Increments