Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up
Problem Submissions Solution

Number of Islands

Difficulty: Medium

Acceptance: 66.00%

Points: 30.00

You are given a 2D grid grid[][] consisting of '1' (land) and '0' (water). Your task is to count the number of islands. An island is formed by connecting adjacent land cells horizontally or vertically. All cells outside the grid are considered water. Return the total number of islands present in the grid.

Topics

Companies

Articles

Examples:

N/A

Constraints:
  • m == grid.length
  • n == grid[i].length
  • 1 = m, n = 300
  • grid[i][j] is either '0' or '1'
Companies:
Amazon Microsoft Apple
Topics:
Recursion
Locked Content
Access Restricted: Please Login to access the code editor and test cases.