Load the Most Units Onto a Truck With Limited Box Slots
Last updated: November 29, 2026
Quick Overview
A delivery truck can carry at most S boxes. You are given box types as (count, units_per_box). Choose boxes to maximize the total units loaded without exceeding S boxes.
Amazon
November 29, 20260
0
0 solved
A delivery truck can carry at most S boxes. You are given box types as (count, units_per_box). Choose boxes to maximize the total units loaded without exceeding S boxes.
A very common Amazon online assessment greedy item, framed around last-mile loading. The grader wants sort-by-value greedy and an explanation of why it is optimal here (every box takes one slot, unlike a weighted knapsack).
What the Interviewer Expects
- Sorts box types by units per box descending
- Takes as many as possible of each type until slots run out
- Explains why greedy is optimal for unit-size items
- Handles S larger than total boxes
- Mentions counting sort when units are small
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Boxes now take different numbers of slots: what changes?
- What if there are two trucks?
- Return which box types to load.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of [count, units] pairs and integer S. Output: max total units using at most S boxes. I would confirm with the interviewer that every box takes exactly one slot regardless of its units, th...
High-Level Design
Every box consumes exactly one slot, so a slot holding a box with more units is always at least as good. Sort types by units descending and fill: take min(count, remaining) boxes of each type. This ...