FastPrepMaximum Units on a Truck

Maximum Units on a Truck

Roblox logoRoblox● EasyNEW GRADOA
Learn

Problem statement

There are boxes.length box types. Type i has boxes[i] available boxes, each containing unitsPerBox[i] units. Every box uses one truck slot, regardless of its unit count.

Load at most capacity boxes and return the maximum total units. You may take any integer number of boxes from each type up to its availability; you may leave slots unused. For this exercise, assume no other weight or volume limit, and do not change either input array.

Function

maximumTruckUnits(boxes: int[], unitsPerBox: int[], capacity: int) → int

Examples

Example 1

boxes = [1,2,3]unitsPerBox = [3,2,1]capacity = 4return = 8

Take one 3-unit box, two 2-unit boxes and one 1-unit box.

Example 2

boxes = [2,3]unitsPerBox = [4,4]capacity = 4return = 16

Any four available boxes have 4 units each.

Example 3

boxes = [2,1]unitsPerBox = [8,5]capacity = 0return = 0

No box fits when the truck has no slots.

Constraints

  • 0 <= boxes.length = unitsPerBox.length <= 1000.
  • 0 <= boxes[i], unitsPerBox[i] <= 1000.
  • 0 <= capacity <= 1000000.
  • The maximum result fits a signed 32-bit integer.

More Roblox problems

See Roblox hiring insights
public int maximumTruckUnits(int[] boxes, int[] unitsPerBox, int capacity) {
    // write your code here
}
boxes[1,2,3]
unitsPerBox[3,2,1]
capacity4
expected8
Checking account…