73. Pacific Atlantic Water Flow
Medium · Graph
You are given an m×n grid representing the heights of land cells. The Pacific Ocean borders the top and left edges, while the Atlantic Ocean borders the bottom and right edges. Water flows from a cell to any adjacent cell (up, down, left, right) that has an equal or lower height. Find all cells from which water can flow to **both** oceans, and return them as a list of [row, col] coordinates sorted in ascending order.
Examples
Example 1 Input: [[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]] Output: [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]] Explanation: Seven cells can flow to both oceans
Example 2 Input: [[1]] Output: [[0,0]] Explanation: Single cell touches both
Constraints
- Standard input/output constraints apply