Try to find the weight and then binary search to find the correct amount of weights.
class Solution:
def shipWithinDays(self, weights: List[int], days: int) -> int:
def solveable(capacity: int) -> bool:
curr = 0
days_taken = 0
for weight in weights:
if curr + weight > capacity:
days_taken += 1
curr = weight
else:
curr += weight
return days_taken < days
left = max(weights)
right = sum(weights)
while left < right:
capacity = (right + left) // 2
if solveable(capacity):
right = capacity
else:
left = capacity + 1
return right