Python data engineering interview problem. Difficulty: advanced. Pattern: Graphs. About 18 minutes. Part of the Pro drill bank.
Count islands of '1' in a grid of '1'/'0'. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement num_islands(grid: list) -> int where grid cells are '1' (land) or '0' (water).
Input: num_islands([['1','1','0'],['1','0','0'],['0','0','1']]) Output: 2 Two connected components of land.
Topics: lakebench, python, dfs, grid.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Count islands of '1' in a grid of '1'/'0'.
Implement `num_islands(grid: list) -> int` where grid cells are `'1'` (land) or `'0'` (water). Example: `[['1','1','0'],['1','0','0'],['0','0','1']]` → `2`. Keep the harness.