⚡️ Tryprepforge
Coding Round 2 Mid programming

**LeetCode #200 - Number of Islands**\nGiven a 2D grid consisting of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You need to implement an algorithm that efficiently counts distinct islands in the grid.\n\n**Function Signature:** `def num_islands(grid: List[List[str]]) -> int:`\n\n**Example 1:**\nInput: `grid = [['1','1','0','0','0'],['1','1','0','0','0'],['0','0','1','0','0'],['0','0','0','1','1']]`\nOutput: `3`\nExplanation: There are 3 islands.\n\n**Example 2:**\nInput: `grid = [['1','1','1'],['0','0','0'],['1','1','1']]`\nOutput: `1`\nExplanation: Only one island exists.\n\n**Constraints:**\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 300

Suggested Answer

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

No credit card required

More Coding Round 2 Interview Prep

Link copied to clipboard