Skip to content

Latest commit

 

History

History

challenge-54

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

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