#C8201. Maximum Area of an Island
Maximum Area of an Island
Maximum Area of an Island
You are given a two-dimensional grid of integers where each cell contains either a 0 or a 1. In the grid, a cell with a value of 1 represents land, whereas a cell with a value of 0 represents water. An island is defined as a group of adjacent land cells connected horizontally or vertically. Your task is to compute the maximum area of an island in the grid.
If there is no island present, the answer should be 0.
The area of an island is the total number of cells with a value of 1 in that island. Mathematically, if you denote the island cells as \(I\), then the area is given by:
[ \text{Area} = \sum_{(i,j)\in I} 1 ]
inputFormat
The first line contains two integers \(n\) and \(m\), which indicate the number of rows and columns in the grid respectively.
The following \(n\) lines each contain \(m\) integers separated by spaces. Each integer is either 0 or 1, representing water and land respectively.
outputFormat
Output a single integer representing the maximum area of an island found in the grid.
## sample4 5
0 1 0 1 0
1 1 0 1 1
0 0 0 1 0
1 1 0 0 0
4