Skip to content

Commit d8777ec

Browse files
authored
Create Maximum Bags With Full Capacity of Rocks.java
1 parent 8b60021 commit d8777ec

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int maximumBags(int[] capacity, int[] rocks, int additionalRocks) {
3+
PriorityQueue<Integer> pq = new PriorityQueue<>();
4+
for (int i = 0; i < capacity.length; i++) {
5+
pq.add(capacity[i] - rocks[i]);
6+
}
7+
while (!pq.isEmpty()) {
8+
if (pq.peek() > additionalRocks) {
9+
return capacity.length - pq.size();
10+
}
11+
additionalRocks -= pq.poll();
12+
}
13+
return capacity.length;
14+
}
15+
}

0 commit comments

Comments
 (0)