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 the eating speed from 1 to max(piles). For each candidate speed, compute total hours needed by summing ceil(pile/speed). If total hours fits within h, try a slower speed. Otherwise increase.
If Koko can finish at speed k, she can also finish at speed k+1 (monotonic). Binary search the speed from 1 to max(piles), checking feasibility each time.
Updated Feb 2026