Skip to main content
mediumBlind 75

Pacific Atlantic Water Flow

Given an m x n matrix of heights Find all cells where water can flow to BOTH Pacific and Atlantic oceans Pacific touches left and top edges, Atlantic touches right and bottom Water flows from cell to adjacent cells with height <= current height Example: [[1,2,3],[4,5,6],[7,8,9]] => [[0,2],[1,2],[2,0],[2,1],[2,2]]

Pacific Atlantic Water Flow is a traversal problem: the hard part is modeling the state you visit. Interviewers love it because it reveals your traversal modeling and your edge-case discipline. Be clear about what a state is; that's the difference between BFS/DFS working or blowing up.

Arrays & HashingGraphsBFS / DFS

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Typing with Coco is free when you sign in, up to a daily limit. Talking with her out loud comes with the $79 pack. Anyone can open the editor and run their code.

1Find Pacific Atlantic Water Flowmedium
2Part 2
3Part 3

Each locked part opens in the editor once the part before it passes.

Based onLeetCode