Problem Statement: Largest Island
You are provided with a non-empty grid consisting of only 0s and 1s. Your task is to determine the maximum area of an island within the given grid.
An island consists of a cluster of 1s (representing land) connected in any of the horizontal, vertical, or diagonal directions. It is assumed that all four edges of the grid are bordered by 0s (representing water).
Input:
The first line contains an integer 'T' denoting the number of test cases.
The first input line of each test case contains two space-separated integers ‘N’ and ‘M’ representing the number of rows and columns of the grid, respectively.
The subsequent 'N' lines represent the rows of the grid. Each row contains 'M' single space-separated integers.
Output:
For each test case, return the maximum area of the island in the grid.
Example:
Input:
T = 1
N = 4, M = 5
grid = [
[1, 1, 0, 0, 0],
[1, 1, 0, 1, 1],
[0, 0, 0, 1, 1],
[0, 0, 0, 0, 0]
]
Output:
4
Constraints:
- 1 <= T <= 100
- 1 <= N <= 50
- 1 <= M <= 50
- 0 <= GRID[i][j] <= 1
Note: If there is no island present in the grid, the maximum area will be 0.

AnswerBot
4mo
Find the maximum area of an island in a grid of 0s and 1s.
Iterate through the grid and perform depth-first search (DFS) to find connected 1s.
Keep track of the area of each island found and return the ...read more
Help your peers!
Add answer anonymously...
Paxcom India Software Developer interview questions & answers
A Software Developer was asked Q. Character Frequency Problem Statement You are given a string 'S' of length 'N'. ...read more
A Software Developer was asked Q. Digit Count In Range Problem Statement Given an integer K, and two numbers A and...read more
A Software Developer was asked Q. Find Two Missing Numbers Problem Statement Given an array of unique integers whe...read more
Popular interview questions of Software Developer
A Software Developer was asked Q1. Character Frequency Problem Statement You are given a string 'S' of length 'N'. ...read more
A Software Developer was asked Q2. Digit Count In Range Problem Statement Given an integer K, and two numbers A and...read more
A Software Developer was asked Q3. Find Two Missing Numbers Problem Statement Given an array of unique integers whe...read more
>
Paxcom India Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

