#K13356. Max Area of Island

    ID: 23894 Type: Default 1000ms 256MiB

Max Area of Island

Max Area of Island

You are given a 2D grid of size \(n \times m\) where each cell contains either a 0 or a 1. A cell containing a 1 is considered part of an island if it is connected to another cell with a 1 either vertically or horizontally. The area of an island is defined as the number of 1 cells present in that connected region.

Your task is to compute the maximum area among all islands present in the grid.

Note: If there is no island, the maximum area is 0.

For example, given the following grid:

0 0 1 0
1 1 1 0
0 1 0 0
1 0 0 0

The maximum area is \(5\) as the island formed by the connected 1s has area 5.

inputFormat

The first line contains two integers, n and m (the number of rows and columns respectively).

The next n lines each contain m space-separated integers (each either 0 or 1), representing the grid.

outputFormat

Output a single integer which is the maximum area of an island in the grid.

## sample
4 4
0 0 1 0
1 1 1 0
0 1 0 0
1 0 0 0
5