Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Binary search on ship capacity from max(weights) to sum(weights). For each candidate capacity, greedily load packages into consecutive days and count days needed. If it fits within d days, try smaller capacity.
If capacity C works, C+1 also works (monotonic). Search space is [max(weights), sum(weights)]. For each candidate, greedily assign packages to days.
Updated Feb 2026