Pacific Atlantic Water Flow
Medium · Graphs · about 25 minutes
Asked at Google, Amazon, Uber, Meta.
An island is a grid of heights. The Pacific touches the top and left edges, the Atlantic the bottom and right edges. Rain flows from a cell to a 4-directional neighbor with equal or lower height, and from edge cells into the adjacent ocean. Return the coordinates [r, c] of every cell from which water can reach both oceans, in any order.