P6 · 2 seconds · 256 MB
Number of Islands
Given a grid of `'1'` (land) and `'0'` (water), return the number of islands. An island is a maximal 4-directionally connected group of land cells.
function numIslands(grid) → number
CONSTRAINTS
- 1 ≤ rows, cols ≤ 50 in this arena (the pattern scales to 1000+)
- grid[r][c] is '1' or '0'
Input: grid = [
["1","1","0","0"],
["1","1","0","0"],
["0","0","1","0"],
["0","0","0","1"]
]
Output: 3
1
2
3
4
5
6
7
8
Arena judges JavaScript in a Web Worker (1s wall-clock, then TLE). Samples are public; submit runs hidden tests too. C++/Python is a later swarm package.