As reported: Intuit Co-Op intern (2026), technical interview coding discussion with time and space complexity: find the connected groups in a binary matrix.
Given an m x n grid of "1" (land) and "0" (water), return the number of islands. An island is a maximal group of land cells connected horizontally or vertically; everything outside the grid is water.
This is LeetCode 200 — Number of Islands.
Example 1
grid = [["1","1","1","1","0"],
["1","1","0","1","0"],
["1","1","0","0","0"],
["0","0","0","0","0"]] -> 1
Example 2
grid = [["1","1","0","0","0"],
["1","1","0","0","0"],
["0","0","1","0","0"],
["0","0","0","1","1"]] -> 3
Constraints: 1 ≤ m, n ≤ 300; each cell is "0" or "1".
Code runner format: one JSON value per line (LeetCode's test-case format): grid. Implement numIslands(grid); the harness prints the count.
Clarifications
- Diagonal neighbours do not connect cells.