Capacity To Ship Packages Within D Days
Problem
A conveyor belt delivers packages in a fixed order, with weights given by the array weights. Every day a single ship departs carrying packages taken from the front of the belt, in order, as long as their total weight does not exceed the ship's capacity. Packages cannot be reordered or split across days. Return the smallest integer capacity that allows all packages to be shipped within days days.
- Between 1 and 100,000 packages, each weighing between 1 and 1,000 units.
daysis at least 1 and at most the number of packages, so a schedule always exists.
Examples
weights = [8, 3, 6, 9, 2, 7, 4], days = 3→15. Loads[8, 3],[6, 9],[2, 7, 4]fit in 3 days; capacity 14 splits the 6 and 9 and needs a fourth day.weights = [4, 6, 2, 5, 3], days = 2→10. Loads[4, 6]and[2, 5, 3], each exactly 10.weights = [2, 9, 1, 1], days = 3→9. Loads[2],[9],[1, 1]; no capacity below 9 can carry the 9-unit package.
Hints
- For a fixed capacity, can you simulate the shipping schedule and count how many days it takes?
- Does a larger ship ever take more days than a smaller one? What structure does that give the set of capacities that work?
- Binary search on the capacity between the heaviest package and the sum of all packages, using the day-count simulation as the predicate.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.