Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 524 Bytes

README.md

File metadata and controls

26 lines (17 loc) · 524 Bytes

Find the number of islands

This problem was asked by Linkedin.

Description

Given a 2-dimensional grid consisting of 1's (land blocks) and 0's (water blocks), count the number of islands present in the grid.

The definition of an island is as follows:

  1. Must be surrounded by water blocks.
  2. Consists of land blocks (1's) connected to adjacent land blocks (either vertically or horizontally).

Assume all edges outside of the grid are water.

Example

Input:
  10001
  11000
  10110
  00000

Output: 3