Fewest Standard Boxes to Exactly Fill a Freight Volume
Last updated: November 29, 2026
Quick Overview
A freight container must be filled exactly with standard box volumes from a given list, with unlimited boxes of each size. Return the fewest boxes needed, or -1 if the exact volume cannot be reached.
Amazon
November 29, 20260
0
0 solved
A freight container must be filled exactly with standard box volumes from a given list, with unlimited boxes of each size. Return the fewest boxes needed, or -1 if the exact volume cannot be reached.
This is the unbounded coin change pattern, framed around Amazon packaging and freight loading. Interviewers check that you rule out greedy with a counterexample, write the bottom-up DP, and discuss reachability and complexity in terms of the target volume.
What the Interviewer Expects
- Show greedy fails with a counterexample
- Define best[v] as fewest boxes for volume v
- Bottom-up recurrence over sizes
- Return -1 for unreachable volumes
- O(V * k) time, O(V) space
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
- Count the number of distinct combinations instead of the minimum.
- What if each box size has a limited supply?
- How would you handle a volume of 10^9 with small box sizes?
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 positive integer sizes and target volume. Output: minimum number of boxes summing exactly to volume, or -1....
High-Level Design
Greedy fails: sizes [1, 5, 6, 9] and volume 11. Greedy picks 9 then 1 and 1 for 3 boxes; the best is 5 + 6 = 2 boxes.
Define best[v] = fewest boxes summing to exactly v. Base best[0] = 0. For e...