workshop private

← all viz

All At Once

viz · created 2026-10-11

Rot spreading across a grid of fruit one ring per minute from four origins at once — the queue is seeded with every rotten cell before the first step, the clock sits on the frame rather than in the cells, and the seams where fronts meet are the proof that no cell is ever claimed twice.

algorithmsinterview-prepcanvas

LC 994 Rotting Oranges, drawn as the thing it actually is: one wave with several origins, not several races. A grid of fresh fruit, a few rotten cells, and a clock on the frame. Every minute the rot advances one ring from every rotten cell simultaneously, and a fresh cell belongs to whichever front reaches it first — wearing that front’s colour forever, because nothing ever re-rots.

The clock lives on the frame, not in the cells, on purpose. A per-cell timestamp invites you to read the board as a distance map, which is true but backwards; what multi-source BFS does is tick a single global minute while the whole frontier moves at once. The tick strip along the top edge is that minute. The answer to the problem is simply where the strip ends — or −1 if, at the end, something is still green and outlined red.

Three things to watch:

Sliders set how many cells start rotten and how many are empty; click any cell to cycle it fresh → rotten → empty and the wave recomputes; space steps, R rerolls.

Reuse

src/all-at-once.js is a framework-free ES module:

No rendering, no timers in the module. The canvas drawing and controls in demo/ are reference code.

Gotchas