Maximum Units on a Truck
Updated
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) → intExamples
Example 1
boxes = [1,2,3]unitsPerBox = [3,2,1]capacity = 4return = 8Take one 3-unit box, two 2-unit boxes and one 1-unit box.
Example 2
boxes = [2,3]unitsPerBox = [4,4]capacity = 4return = 16Any four available boxes have 4 units each.
Example 3
boxes = [2,1]unitsPerBox = [8,5]capacity = 0return = 0No 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 Online Assessment questions
- Centered Block Placement QueriesOA · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
- Factory Batch Profit (Game Adaptation)OA · Seen Sep 2026
- Nested Recipe Blocks (Game Adaptation)OA · Seen Sep 2026
- Vehicle Builds for Required Terrain (Game Adaptation)OA · Seen Sep 2026
- Track Received Byte RangesOA · Seen Sep 2026
- Inventory Discount TrackerOA · Seen Sep 2026
- Break a PalindromeOA · Seen Jun 2026
- Count Pairs Differing in One DigitOA · Seen Oct 2025
- Find Zero Cells in a 2×2 GridOA · Seen Oct 2025
Similar questions at other companies
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
- Server ManagementRippling · OARippling interview questions
- Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
- Economical TripAccenture · OAAccenture interview questions
- Minimum Pile Reduction StepsAmerican Express · OAAmerican Express interview questions
- Find Maximum Number of Subjects Passed (AS Intern, but it may apply to other interns) 🍋Amazon · OA
- Maximum Production Within PowerZomato / Eternal · OAZomato / Eternal interview questions
- Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
- Compute Walking DistanceTikTok · OATikTok interview questions