My Leetcode tour: 1011. Capacity To Ship Packages Within D Days
1 min readAug 18, 2019
If we have unlimited days, the answer will be max(weights).
If we just have one day, the answer will be sum(weights).
Now, we have an interval between max(weights) and sum(weights).
sorted list or interval => we can use the binary search!
This question is not very intuitive because the interval is not obvious to find and the weights are not sorted. It is difficult to come up with the binary search.
The time complexity is O(N*log(sum(weights) — max(weights)))
sum(weights) — max(weights) is a constant number, but it could be too large to seem it as a constant.