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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
1D dynamic programming
unbounded knapsack
coin change
greedy counterexample
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported