Code RoomShip capacity
MediumPrep Room Coding #1125

Ship capacity

CodingDistributed systemsAlgorithms & data structuresMid–Senior~24 min

A conveyor belt has packages that must ship within days days. weights[i] is the i-th package's weight; packages must be loaded in given order. Each day you load the ship with packages (in order) without exceeding its capacity. Return the least weight capacity of the ship that allows all packages to ship within days days. 1 <= days <= len(weights) <= 5e4.

Implement
ship_within_days(weights: list[int], days: int) → int
Examples
in[[1,2,3,4,5,6,7,8,9,10],5]out15
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 24 min
InputExpectedGot
[[1,2,3,4,5,6,7,8,9,10],5]15not run yetsample