Depth-First Search pattern
Number of Islands
Given a grid of land and water cells, count the number of islands, where an island is a group of land cells connected 4-directionally and surrounded by water. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 200
- 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 200
Medium
The approach
- 01 Scan + DFS sink O(R·C)O(R·C) space
What you will learn
- How to read Number of Islands and spot the depth-first search pattern in it
- Scan + DFS sink: 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 Number of Islands 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.