โ† Trees, Graphs & DP
#7 most askedVery commonMediumGrid graph

Number of Islands

New to Grid graph? Learn it from scratch first
Grids & Matrix Traversal โ†’
๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

A grid of "1" (land) and "0" (water). Count the islands: groups of land connected up, down, left or right.

๐Ÿงช Practice

Write your solution, then press Run tests. Explain your approach out loud as you go.

Python
def num_islands(grid):
    pass

Output appears here. Press Run or Ctrl/โŒ˜ + Enter.

Try it first. Struggling for a few minutes is how it sticks.