Depth-First Search pattern
Pacific Atlantic Water Flow
Given a grid of cell heights where the Pacific Ocean borders the top and left edges and the Atlantic borders the bottom and right edges, return all cells from which water can flow to both oceans, moving only to equal-or-lower neighboring cells. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 417
- Medium
- 1 approach
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
Depth-First SearchLeetCode 417
Medium
The approach
- 01 Reverse DFS from both oceans O(R·C)O(R·C) space
What you will learn
- How to read Pacific Atlantic Water Flow and spot the depth-first search pattern in it
- Reverse DFS from both oceans: O(R·C) time, O(R·C) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Depth-First Search
See Pacific Atlantic Water Flow run, step by step
Sign in and this page opens on the animation, with all 18 Depth-First Search problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.