▸1flood(r, c, reach):2 reach[r][c] = true3 for each neighbour with height >= heights[r][c]:4 if not reach[nr][nc]: flood(nr, nc, reach)5seed Pacific from top row + left col6seed Atlantic from bottom row + right col7// intersect8answer = cells where pacific && atlantic9return answer
- ruleflow to ≤ neighbour
- trickreverse from oceans