Fill the Truck https://leetcode.com/discuss/interview-question/918270/
I passed the 2 base test cases I was getting a run time error and couldn't find it.
public int filltheTruck(int num, List<Integer> boxes, int unitSize, List<Integer> unitsPerBox, int truckSize) {
if (boxes.size() == 0 || unitsPerBox.size() == 0) return 0;
PriorityQueue<Integer> pq = new PriorityQueue<Integer>(Collections.reverseOrder());
for (int i = 0; i < boxes.size(); i++) {
for (int j = 0; j < boxes.get(i); j++) {
pq.add(unitsPerBox.get(i));
}
}
int maxUnits = 0;
while (truckSize > 0 && !pq.isEmpty()) {
maxUnits += pq.poll();
truckSize--;
}
return maxUnits;
}