Back to all patterns

DFS / BFS

3 problems • Practice on LeetCode to earn credits

About This Pattern

Master the DFS / BFS pattern by practicing these problems organized by difficulty.Focus on the Key Signals - these are the indicators that tell you when to use this pattern.

Easy (1)

Flood Fill

Perform flood fill starting from pixel [sr, sc], changing connected pixels to new color.

Key Signals:

Connected componentsColor fillGrid traversal

Medium (2)

Number of Islands

Count number of islands in a 2D grid (connected land cells).

Key Signals:

Connected componentsMark visitedDFS/BFS from each unvisited land
Max Area of Island

Find the maximum area of an island in a 2D grid.

Key Signals:

Track area during traversalReturn maxSimilar to count islands