Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Number of Islands

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).

Constraints

  • 4-directional connectivity.

Examples

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

advanced

Number of Islands

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.