You are given an array weights[] where weights[i] represents the weight of the ith package, and an integer days representing the number of days within which all packages must be shipped. Packages must be shipped in the given order, and each day you can ship packages whose total weight does not exceed the ship’s capacity. Return the minimum ship capacity required to ship all packages within the given number of days.
Example 1
Input: weights = [1,2,3,4,5,6,7,8,9,10], days = 5
Output: 15
Explanation: One possible way is: Day 1 ? [1,2,3,4,5] ? total weight = 15 Day 2 ? [6,7] ? total weight = 13 Day 3 ? [8] ? total weight = 8 Day 4 ? [9] ? total weight = 9 Day 5 ? [10] ? total weight = 10 The minimum capacity required is 15.
Example 2
Input: weights = [3,2,2,4,1,4], days = 3
Output: 6
Explanation: One possible way is: Day 1 ? [3,2] ? total weight = 5 Day 2 ? [2,4] ? total weight = 6 Day 3 ? [1,4] ? total weight = 5 The minimum capacity required is 6.
Example 3
Input: weights = [1,2,3,1,1], days = 4
Output: 3
Explanation: One possible way is: Day 1 ? [1,2] ? total weight = 3 Day 2 ? [3] ? total weight = 3 Day 3 ? [1] ? total weight = 1 Day 4 ? [1] ? total weight = 1 The minimum capacity required is 3.
Sign in to write, run, and submit your solution against the full test suite.