Approach hintTry it first, then revealHide
Scan the grid; each unvisited land cell starts a new island, and a DFS or BFS from it marks every connected land cell as visited.
Scan the grid; each unvisited land cell starts a new island, and a DFS or BFS from it marks every connected land cell as visited.