The Archipelago Count
HardAcc. 82.1%
+50 XP 25
Connectivity in Grids
An island is surrounded by water (0s) and is formed by connecting adjacent 1s horizontally or vertically.
The Assignment
Your function receives a 2D grid of strings "1" (land) and "0" (water).
- Scan every cell.
- If you find a "1", count a new island and spark a DFS to turn all connected "1"s into "0"s.
- Print the final count.
01EXAMPLE 1
Input
[["1","1","0"],["0","0","1"]]Output
2Explanation: One island at top-left, one at bottom-right.
Constraints
- O(M * N) time complexity.
GraphsGrid
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
grid[["1","1","0"],["1","1","0"],["0","0","1"]]
Expected Output
2
Click RUN to test your solution