Number of Islands II — union-find
Add land one cell at a time. Each new cell starts its own island, then merges with any land it touches.
Try:
0
islands
answer after each addition