🚀 Phases 1–5 are live — Days 1–17 cover the foundations and the algorithmic patterns. See the roadmap →
Day 10 - Graph Traversal (DFS and BFS)Practice QuestionsOverview

DFS & BFS Practice Questions

Ten interview classics. Each one is “DFS or BFS plus a small twist.” Recognizing which algorithm to use is half the work.

For each problem, before peeking at the solution, ask:

  • Shortest / minimum steps? → BFS.
  • Count / detect / enumerate? → DFS.
  • Spread from multiple starts simultaneously? → multi-source BFS.

Most of these problems have nicknames in the interview circuit. Recognize them and the solution writes itself.

Medium

ProblemPatternStatus
Number of IslandsGrid DFS — count component startsAvailable
Max Area of IslandGrid DFS — aggregate during traversalAvailable
Clone GraphDFS / BFS + hash-map memoAvailable
Course ScheduleDirected cycle detection (DFS or BFS)Available
Is Graph Bipartite?BFS 2-coloringAvailable
Surrounded RegionsBorder-anchored DFSAvailable
Pacific Atlantic Water FlowMulti-source DFS (reverse-flood)Available
Walls and GatesMulti-source BFSAvailable
Shortest Path in Binary MatrixBFS with 8 directionsAvailable

Hard

ProblemPatternStatus
Word LadderBFS on word transformationsAvailable

More Practice (Coming Soon)

ProblemPatternStatus
Course Schedule IITopological sort (Kahn’s)Coming Soon
Open the LockBFS on state spaceComing Soon
Word Ladder IIBFS + path reconstructionComing Soon
Minimum Number of Days to Make BouquetsBinary search + BFSComing Soon
01 MatrixMulti-source BFSComing Soon
Shortest BridgeDFS to find one island + BFSComing Soon
Cheapest Flights Within K StopsModified BFS / Bellman-FordComing Soon
Redundant ConnectionUnion-FindComing Soon