Number of islands
Scan the grid cell by cell. Land nobody has visited yet means a new island: a BFS from there visits all of it, so the rest of that island is skipped by the scan. The number of BFS runs is the number of islands.
Scan the grid cell by cell. Land nobody has visited yet means a new island: a BFS from there visits all of it, so the rest of that island is skipped by the scan. The number of BFS runs is the number of islands.