As reported: CrowdStrike London, Senior Engineer / Engineer-3 loop (2025), coding round: Number of Islands, solved with DFS.
Given an m × n grid of '1' (land) and '0' (water), return the number of islands. An island is a group of land cells connected horizontally or vertically; the grid is surrounded by 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.
Code runner format: one JSON value: grid (LeetCode's format). Implement numIslands(grid); the harness prints the count.