Pacific Atlantic Water Flow
A height grid borders the Pacific on top and left and the Atlantic on bottom and right. Water may move orthogonally to cells of equal or lower height. Return coordinates from which water can reach both oceans, in any order.
Example 1
0,01
0,12
1,04
1,13
heights = [[1,2],[4,3]][[0,1],[1,0],[1,1]]Explanation
Top-right and bottom-left touch both oceans; bottom-right flows to top-right at height 2 and also touches Atlantic boundaries.
Example 2
0,07
heights = [[7]][[0,0]]Explanation
The single cell borders both oceans.
Example 3
0,02
0,12
1,02
1,12
heights = [[2,2],[2,2]][[0,0],[0,1],[1,0],[1,1]]Explanation
Equal heights permit movement across the whole grid, so all cells reach both oceans.
Constraints
- 1 <= rows, columns <= 200
- Heights are 0..100000
Function contract
pacificAtlanticArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[[1,2],[4,3]]