-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_2233.java
More file actions
29 lines (22 loc) · 753 Bytes
/
_2233.java
File metadata and controls
29 lines (22 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.github.aditya;
import java.util.PriorityQueue;
public class _2233 {
// 363 ms, faster than 81.98%, memory 52.5 MB, less than 95.67%
// Time Complexity O(k * logn) and Space Complexity O(n)
class Solution {
public int maximumProduct(int[] nums, int k) {
PriorityQueue<Integer> minHeap = new PriorityQueue<>();
for (int num : nums)
minHeap.add(num);
while (k > 0) {
int min = minHeap.poll();
minHeap.add(min + 1);
k--;
}
long result = 1;
while (!minHeap.isEmpty())
result = (result * minHeap.poll()) % 1000000007;
return (int) result;
}
}
}