Code Room
CodingMediumcod-g558
Subject Binary searchLevel Mid–Senior~24 minCommon in Distributed systems · Algorithms & data structures interviewsIndustries Software development, Technology

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.