Pacific Atlantic Water Flow
There is an m x n rectangular island that borders both the Pacific Ocean and the Atlantic Ocean. The Pacific Ocean touches the island's left and top edges, and the Atlantic Ocean touches its right and bottom edges. You are given an m x n integer matrix heights where heights[r][c] is the height above sea level of the cell at coordinate (r, c).
Rain water flows from a cell to a neighboring cell (north, south, east, or west) only when the neighbor's height is less than or equal to the current cell's height, and any cell adjacent to an ocean can drain into that ocean. Return a list of coordinates [r, c] for every cell from which water can flow to both the Pacific and Atlantic oceans.
Toggle the views above to trace which cells drain to each ocean. The cells that reach both are the answer you must return.
heights = [[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]]
[[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]
heights = [[2,1],[1,2]]
[[0,0],[0,1],[1,0],[1,1]]