Dashboard
LC #417

Pacific Atlantic Water Flow

Pattern · ?AmazonGoogleMeta

Problem

Find all cells from which water can flow to both the Pacific and Atlantic oceans.

Constraints

  • 1 ≤ m, n ≤ 200
  • 0 ≤ heights[i][j] ≤ 10⁵

Example

Input
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]]
Output
[[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]
Why
Water flows to a lower or equal neighbor. Pacific: top/left border. Atlantic: bottom/right border

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗