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
Sort basket positions, then binary search the minimal spacing candidate. A greedy pass checks whether we can place m balls with at least that spacing.
If a spacing d is feasible, any smaller spacing is also feasible. So the optimum is found by binary searching the highest feasible spacing.
Updated Feb 2026