Close
Topic list
Find Number Of Islands
MEDIUM
34 mins
Arrays
Topics (Covered in this problem)
Problem solved
Skill meter
Arrays
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Find Number Of Islands

Contributed by
Ankit Kharb
Medium
0/80
Avg time to solve 34 mins
Success Rate 60 %
Share

## Problem Statement

#### A group of connected cells having value 1 is called an island. Your task is to find the number of such islands present in the matrix.

Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````4 5
0 1 1 0 0
1 0 0 1 0
0 0 1 0 0
1 0 0 0 1
``````
##### Sample Output 1 :
``````3
``````
##### Explanation For Sample Input 1 :
``````The first island of connected 1s is signified by: {0, 1}, {0, 2}, {1, 0}, {1, 3}, {2, 2}.

The second island being: {3, 0}.

The third island being: {3, 4}.
``````
##### Sample Input 2 :
``````4 4
1 0 0 1
0 1 1 0
0 1 1 0
1 0 0 1
``````
##### Sample Output 2 :
``````1
``````
Auto
Console