← Visualizers
Binary Search — Answer Space LeetCode 875

Koko Eating Bananas / visualized

There's no array to search here — the search space is every possible eating speed, from 1 to the largest pile. canFinish(speed) is monotonic: if a slow speed finishes in time, so does every faster one. That monotonicity is what makes binary search valid on an answer space instead of an array.

Execution

idle
L
M
H
piles (hours needed at current candidate speed)
Press Run to begin.
0 / 0
Speed

Java · running line

lo mid (candidate speed) hi feasible
O(n · log(max(piles))) time · O(1) space  ·  binary search the answer, not the array — the array only shows up inside the feasibility check.