Back to course home
0% completed
Biggest Island (easy)
Problem Statement
Given a 2D array (i.e., a matrix) containing only 1s (land) and 0s (water), find the biggest island in it. Write a function to return the area of the biggest island.
An island is a connected set of 1s (land) and is surrounded by either an edge or 0s (water). Each cell is considered connected to other cells horizontally or vertically (not diagonally).
Example 1
Input: matrix =
![Image](/_next/image?url=https%3A%2F%2Fstorage.googleapis.com%2Fdownload%2Fstorage%2Fv1%2Fb%2Fdesigngurus-prod.appspot.com%2Fo%2FdocImages%252F6388d8940cc1849dcbc27fe3%252Fimg%3Aeebd03-24fa-2732-4d86-a22a12dc78ef.jpg%3Fgeneration%3D1669912802906830%26alt%3Dmedia&w=3840&q=75)
Output: 5
Explanation: The matrix has three islands. The biggest island has 5 cells .
![Image](/_next/image?url=https%3A%2F%2Fstorage.googleapis.com%2Fdownload%2Fstorage%2Fv1%2Fb%2Fdesigngurus-prod.appspot.com%2Fo%2FdocImages%252F6388d8940cc1849dcbc27fe3%252Fimg%3A1ba2fbc-b7a7-b1e7-e22d-1a556df38.jpg%3Fgeneration%3D1669912869594259%26alt%3Dmedia&w=3840&q=75)
Constraints:
m == matrix.length
n == matrix[i].length
1 <= m, n <= 50
matrix[i][j] is '0' or '1'.
Try it yourself
Try solving this question here:
Python3
Python3
. . .
Mark as Completed