Back to problems

Pacific Atlantic Water Flow

Algorithm · Medium

You are given an m x n integer matrix heights that represents the elevations on an island. The entry heights[r][c] gives the height of the cell at row r, column c. The Pacific Ocean lies along the top and left edges of the grid, while the Atlantic Ocean lies along the bottom and right edges. Rainwater on any cell can flow to an adjacent cell (horizontally or vertically) provided that the neighbor's height does not exceed the current cell's height. A cell that sits on the top…

Checking your access…