1011. Capacity To Ship Packages Within D Days
class Solution:
def shipWithinDays(self, weights: List[int], days: int) -> int:
left, right = max(weights), 25000000 # 500 * 5 * (10 ** 4)
while left <= right:
mid = (left + right) // 2
capacity = mid
day = 1
for weight in weights:
if capacity - weight < 0:
capacity = mid
day += 1
capacity -= weight
if day > days:
left = mid + 1
else:
right = mid - 1
return left