Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Count Islands and Make a Large Island



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Count Islands in Grid

Count Islands in Grid

Problem Statement

You are given a 2D grid consisting of characters '1' representing land and '0' representing water. Your task is to determine how many distinct islands exist in the grid. An island is defined as a group of horizontally or vertically adjacent lands surrounded by water. The edges of the grid are considered to be water.

Examples

Example 1:

Grid:
11100
11000
10011
00000

Number of islands: 2

Example 2:

Grid:
10100
10100
00010
01110

Number of islands: 4

Constraints

  • Grid rows: 1 to 150
  • Grid columns: 1 to 150
  • Each cell is either '1' or '0'