Maximum Units on a Truck
A easy-tier problem at 74% community acceptance, tagged with Array, Greedy, Sorting. Reported in interviews at IBM and 2 others.
Maximum Units on a Truck is an easy greedy problem that hits your assessment unprepared if you've only memorized binary search. IBM, Arista, and JP Morgan ask it, and you'll see it pop up when you're tired mid-OA. The trick is dead simple once you see it, but the framing as a 'truck loading' problem throws candidates who haven't practiced sorting arrays by a second dimension. With a 74% acceptance rate, this is a confidence-builder you can't afford to blank on. StealthCoder surfaces the solution in seconds if the pattern doesn't click instantly.
Companies that ask "Maximum Units on a Truck"
Maximum Units on a Truck is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThis is pure greedy sorting. You sort boxes by units per box in descending order, then load greedily until the truck is full. The trap is overthinking it: candidates waste time considering which boxes to skip or building a DP solution when the problem doesn't need it. The real complexity is handling the last box correctly (you can only fit truckSize - currentLoad units, not the full box quantity). The topics are Array, Greedy, and Sorting, and you need all three: sort the array by a custom key, then iterate through it greedily. Most wrong submissions come from off-by-one errors on the truck capacity check, not from algorithm confusion. If you blank on 'just sort by units descending' during the live assessment, StealthCoder runs invisibly and hands you the working code.
Pattern tags
You know the problem.
Make sure you actually pass it.
Maximum Units on a Truck recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Units on a Truck interview FAQ
Is Maximum Units on a Truck really an easy problem or a medium trap?+
It's genuinely easy. The 74% acceptance rate reflects that. The trap is overthinking the greedy choice, not the algorithm itself. Sort descending by units per box, load greedily, handle the final box capacity. That's it. Most failures are minor off-by-one bugs, not algorithmic confusion.
Why do IBM, Arista, and JP Morgan ask this?+
It tests whether you recognize greedy as the right approach and handle array sorting by a secondary attribute. Both are baseline skills. It's also fast to code correctly, so they use it as a filter for candidates who can't translate problem statements into clean code under pressure.
What's the trick I'm missing if I keep getting wrong answer?+
You're likely not capping the final iteration correctly. If truckSize is 10 and you have 8 units loaded and a box with 5 units, you can only load 2 units, not all 5. Check your logic on the last box: use min(boxUnits, remainingCapacity) or a similar guard.
Do I need dynamic programming for this, or is greedy actually optimal?+
Greedy is optimal and sufficient. Since you want to maximize total units and each box is independent, loading the highest-unit boxes first is always the best choice. DP is overkill and will time out or waste memory on a problem that sorts and iterates in one pass.
How does this relate to other greedy and sorting problems I should drill?+
This is the entry-level greedy sort. It's easier than activity selection or interval scheduling. If you can code this cleanly in under 10 minutes, you're ready for medium greedy problems. The sorting-by-custom-key pattern appears across many array problems, so nailing it here pays dividends.
Want the actual problem statement? View "Maximum Units on a Truck" on LeetCode →