boxTypes
array in descending order based on the number of units per box.totalUnits
to 0 to keep track of the total number of units added to the truck.boxTypes
array.
a. Calculate the number of boxes that can be added to the truck: min(remainingTruckSize, numberOfBoxesi)
.
b. Update totalUnits
by adding the product of the number of boxes added and numberOfUnitsPerBoxi
.
c. Decrease truckSize
by the number of boxes added.
d. If truckSize
reaches 0, break out of the loop as the truck is full.totalUnits
as the maximum total number of units that can be put on the truck.