Minimum Truck Capacity to Ship All Packages Within D Days
Last updated: November 29, 2026
Quick Overview
Packages on a conveyor must be loaded in order onto one truck per day, and a day's load cannot exceed the truck's capacity. Given package weights and a number of days D, return the smallest integer capacity that ships everything within D days.
Amazon
November 29, 20260
0
0 solved
Packages on a conveyor must be loaded in order onto one truck per day, and a day's load cannot exceed the truck's capacity. Given package weights and a number of days D, return the smallest integer capacity that ships everything within D days.
A binary search on the answer problem that Amazon interviewers like because it fits fulfillment so naturally. They check that you spot monotonicity (larger capacity never needs more days), pick tight search bounds and write a correct greedy feasibility check.
What the Interviewer Expects
- Notice feasibility is monotone in capacity
- Set bounds to max(weights) and sum(weights)
- Write a greedy day-count check
- Use a lower-bound binary search pattern without off-by-one errors
- Trace one example by hand
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
- What if packages can be loaded in any order rather than conveyor order?
- How would you handle a minimum load per day as well?
- How would you return the actual day boundaries?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Weights: non-empty list of positive ints. 1 <= D <= len(weights). Return an int capacity. Order must be preserved, and each package goes wholly on one day....
High-Level Design
Feasibility: for a capacity c, greedily fill each day until the next package would overflow, then start a new day. Greedy filling minimizes days for a fixed c because delaying a split never helps. If ...