Number of Islands
Count connected components on a grid with flood fill from every unvisited land cell.
Flood Fill: Count the islands
Island 1. Pop (0, 0). 2 neighbours still land: (1, 0), (0, 1). Paint and queue them.
Cost
- Best
- O(r * c)
- Average
- O(r * c)
- Worst
- O(r * c)
- Space
- O(r * c)
Before this
Taught by the same lesson
Flood Fill covers these too, in the same run.