How do you count them without counting the same island twice? you use a loop and a traversal.
Loop through every cell in the grid.
If you find a cell that is '' (Land): - you increment your island_count. - you immediately trigger a traversal (DFS or BFS) from that cell. - As you traverse the island, you mark every cell you visit as '' (Water) or '' (Visited).
By erasing the island as you visit it, your main loop will never accidentally count it again.