Problem
An island is a grid of heights. The Pacific Ocean touches its top and left edges, the Atlantic touches its bottom and right edges. Rain on a cell can flow to a side neighbour whose height is less than or equal to the current one, and from any edge cell straight into the ocean beside it. Return every [row, col] from which water can reach both oceans, in any order.
Example 1
heights = [[1, 2, 2, 3, 5],
Example 2
[3, 2, 3, 4, 4],
Example 3
[2, 4, 5, 3, 1],
Example 4
[6, 7, 1, 4, 5],
Example 5
[5, 1, 1, 2, 4]]
Example 6
→ [[0, 4], [1, 3], [1, 4], [2, 2], [3, 0], [3, 1], [4, 0]]
Example 7
- Input
- heights = [[1]]
- Output
- [[0, 0]]
Constraints
1 <= heights.length, heights[i].length <= 2000 <= heights[i][j] <= 10^5