Flood Fill

Graphs · DFS · Visit connected neighbours safely · Easy · about 20 min

Why it matters

Graphs become approachable when you see them as nodes plus allowed moves.

How it connects

A grid is a graph in disguise. Your tree recursion now has up to four neighbours.

Try first

What condition prevents the algorithm from returning to a cell it already changed?

Interview cue

Marking visited cells ensures each reachable cell is processed once.