AlgoUniversity
  • Go Back
Discussion
Max Area Of Island :

Author

hardik kapoor

Difficulty Level : Easy

Submissions : 218

Asked In : Amazon

Marks :10

: 3 | : 0

You are given an n x m binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

The area of an island is the number of cells with a value 1 in the island.

Return the maximum area of an island in grid. If there is no island, return 0.

Input

The first line contains N (1 <= N <= 1e4) and M (1 <= M <=1e4)

The next N lines contains M integers, 0 or 1 representing the grid.

N*M <= 1e4 for all test cases

Output

Output a single integer, max are of the island.

Examples

Input
5 5
0 0 0 1 0
0 0 1 1 1
0 1 1 1 1
0 0 0 0 0
0 0 0 0 0
Output
8
Input
5 5
0 0 1 0 0
0 1 1 0 1
0 0 0 0 1
0 0 1 0 0
0 0 0 0 1
Output
3
Input
3 3
0 0 0
0 0 0
0 0 0
Output
0

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.