core practice · coding problem

Number of Islands

LeetCode #200 — Number of Islands. Solve on LeetCode, then implement here if you want it in your drill queue. https://leetcode.com/problems/number-of-islands/

The mechanism

Most graph problems are one of a few templates: reachability/components (DFS/BFS), shortest path (BFS for unweighted, Dijkstra for weighted), ordering (topological sort), or connectivity (union-find). The skill is recognizing the template and modeling the input as nodes and edges.

Study Graphs

Expected evidence

Pass all LeetCode test cases for this problem.

Try this drill in the practice workspace →

Hints when you need them
  • Pattern hint: graphs.
  • Start with brute force, then optimize time/space.
  • Write down invariants before coding.

Watch for these mistakes

  • No visited set — revisiting nodes and looping forever
  • Using DFS for shortest path on an unweighted graph instead of BFS
  • Not handling disconnected components

Check the sources

Practice the same mechanism

Browse all practice briefs