Capacity to Ship Packages Within D Days
A conveyor belt has packages that must be shipped within days days. The i-th package has weight weights[i]. Each day you load packages onto the ship in the given order without exceeding the ship's maximum weight capacity. Return the least weight capacity of the ship that lets all packages be shipped within days days.
Open official problem prompt ↗Find the smallest ship capacity that still delivers every package, in order, within the day limit.
Packing moving boxes of a fixed size across a set number of days: a bigger box lets you finish sooner, so you shrink the box size to the smallest that still finishes on schedule.
- Input
- weights = [1,2,3,4,5,6,7,8,9,10], days = 5
- Output
- 15
- Why
- With capacity 15 the greedy loads are (1,2,3,4,5)=15, (6,7)=13, (8), (9), (10) - exactly 5 days. Any smaller capacity forces a sixth day, so 15 is the minimum.
1 <= days <= weights.length <= 5*10^41 <= weights[i] <= 500Packages must be shipped in their given orderEach day's total load cannot exceed the ship capacity