Problem
Packages with weights weights sit on a conveyor belt and must be shipped in the given order. Each day you load the ship with packages from the front of the belt until adding the next one would exceed the ship's capacity. Return the least weight capacity that gets every package shipped within days days.
Example 1
- Input
- weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], days = 5
- Output
- 15
Example 2
- Input
- weights = [3, 2, 2, 4, 1, 4], days = 3
- Output
- 6
Example 3
- Input
- weights = [1, 2, 3, 1, 1], days = 4
- Output
- 3
With capacity 15 in the first example the days are [1..5], [6, 7], [8], [9], [10].
Constraints
1 <= days <= weights.length <= 5 * 10^41 <= weights[i] <= 500