workshop private

← all creations

Monotone

viz · created 2026-09-23

Binary search on the answer drawn as the predicate instead of the array — the LC 875 piles sliced into hours at a speed you drag, and under them one boolean strip that fills in by probe and by implication, incapable of holding a green cell left of a red one, with the search's brackets narrowing onto the single boundary it has.

algorithmsinterview-prepcanvas

Koko Eating Bananas (LC 875) is the canonical “binary search on the answer” problem, and every explainer draws the piles. The piles are not the interesting object. Nothing about them is sorted and sorting does not help. The sorted thing is the predicatecan she finish every pile at speed k within h hours? — which over k = 1 .. max(piles) reads F F … F T T … T with exactly one boundary, because hours(k) = Σ ⌈pile / k⌉ can only fall as k rises. That strip is what the search is searching, so that is what the piece draws.

Three layers, top to bottom:

Two switches. lo = ⌈Σ piles / h⌉ replaces the lazy lower bound with the one the constraints hand you — at most k bananas an hour means k · h ≥ Σ piles — drawn as an amber dashed line, and usually worth a probe. Reveal strip ghosts the full predicate in behind the known cells, so you can see that what the probes implied was true, and that nothing else was ever needed.

Presets: the three LC examples and random piles. probes the next mid, space runs the search, r resets, v reveals the strip. The h slider re-cuts the boundary; the strip is recomputed and the probes cleared.

Reuse

src/monotone.js is a framework-free ES module:

No rendering or timers in the module; the canvas demo is reference code.

Gotchas