Loading...
Given a 2D grid of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and formed by connecting adjacent land cells horizontally/vertically.
Input: rows of comma-separated 1/0.
1,1,1,1,0 1,1,0,1,0 1,1,0,0,0 0,0,0,0,0
1
1 1 1 1 0 1 1 0 1 0 1 1 0 0 0 0 0 0 0 0
* We identify the connected land cells (horizontally/vertically) to form islands. In this case, all the '1's are connected, forming a single large island.
* The number of islands is counted, which in this case is $1$ since all the land cells are part of the same island.
* The final output is the total count of islands, which is $\boxed{1}$.