Skip to content

Count the number of islands in the 2D array (which visualize a map)

License

Notifications You must be signed in to change notification settings

jnicram/find-number-of-islands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

find-number-of-islands

At beginning of this task you are given a two dimensional array which visualize a map. Each element of this array will take one of the following values: 0 (which represents water), 1 (which represents land).

These values will form islands on water.

For example:

0 0 0 0 0 0 0 0 0

0 1 0 0 0 0 0 0 0

1 1 1 0 0 0 1 0 0

1 1 0 0 0 1 1 1 0

0 0 0 0 0 1 1 0 0

0 0 1 0 0 0 0 0 0

1 1 0 0 0 0 0 0 0

0 0 0 0 0 1 1 0 0

(This example illustrates 4 islands. Counting from left upper corner: First Island is made of six land elements, Second Island is also made of six land elements. Third island consists of 3 elements, and last one is made of two elements).

Write a short program, which will count the number of islands. Following data structure could be varying in size. Take into assumption, that data structure given to you could be very large in size, so beware of implementation that could result in stack overflow or out of memory exception.

About

Count the number of islands in the 2D array (which visualize a map)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages