Pacific Atlantic Water Flow, traced one call at a time

Run the rain backwards: start from each ocean's edge and let dfs climb to any neighbour that is at least as high. Everything the Pacific search reaches drains to the Pacific; same for the Atlantic. The answer is the cells both searches reach.

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Recursion tree

Two forests: Pacific seeds, then Atlantic seeds · hover a call to find its cell

not called yet running now paused, waiting on a child reached (Pacific search) reached (Atlantic search) ✕ = returned at once: sea, seen or lower

Call stack

Top frame runs; the rest are paused

Island

Numbers are heights; the ring around the grid is ocean

Pacific (top, left) Atlantic (bottom, right) in pac in atl in both = answer darker = higher

result cells in both pac and atl

Keyboard: ← → step, Space play or pause. Grids up to 6×6. Use the Atlantic ⏭ and Result ⏭ buttons to jump between the two searches. Note the second call on each corner returns at once because it is already in the set.