The Minimum Space Wasted From Packaging problem gives you packages of various sizes and several suppliers, each offering boxes in specific sizes. A package fits in a box if the box size ≥ package size. The wasted space for a package-box pair is box size - package size. You must assign every package to exactly one box from a single supplier, minimizing total wasted space. This Minimum Space Wasted From Packaging interview question combines sorting with binary search in a layered way.
IMC, Two Sigma, and Amazon ask this hard problem because it tests multi-component algorithm design: sorting, binary search, and prefix sums used together. Naïve O(n×m×k) approaches are far too slow; the efficient solution requires knowing how to use binary search to assign groups of packages to the smallest fitting box from each supplier. The array, sorting, binary search, and prefix sum interview pattern all play a role.
Sort packages and each supplier's box sizes. For each supplier, use binary search to find the smallest box that can fit each "group" of packages (all packages fitting into the same box size). Use prefix sums of package sizes to quickly compute total waste for a range of packages assigned to one box. Try all suppliers and take the minimum total waste. Time: O(n log n + sum of (m_i log n)) where m_i is each supplier's number of box sizes.
Packages: [2, 3, 5], Supplier A boxes: [4, 8].
Compare with other suppliers to find the minimum.
Problems requiring "assign items to containers with minimum cost" often combine sorting with binary search for grouping. Practice the pattern: sort items, sort containers, for each container boundary find the range of items it covers via binary search, compute cost for that range using prefix sums. This three-component approach appears in several hard sorting problems. Internalize each component separately before combining them under time pressure.