Number of Islands — DFS flood fill
Scan for land; each time you hit an unvisited cell, count one island and sink everything connected to it.
Try:
← Prev
Next →
▶ Play
Reset
0
islands
water
unvisited land
current cell
flooded island