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.
Be the first one to answer
Add answer anonymously...
Top Paxcom India Software Developer interview questions & answers
Popular interview questions of Software Developer
>
Paxcom India Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app