Medium40 pts
Count Islands
Given a 2D grid of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. Use BFS or DFS to explore and mark visited cells. Example: 11110 11010 11000 00000 → 1 island
Input
Line 1: m n (rows and columns). Next m lines: strings of 0s and 1s.
Output
The number of islands.
Sample
4 5 11110 11010 11000 00000
Expected
1
Loading editor…
Output
No output yet. Run your code to see results.