#C6527. Maximum Area of Island
Maximum Area of Island
Maximum Area of Island
Given an grid of characters where each cell is either '1' (land) or '0' (water), an island is a group of connected '1's (cells connected horizontally or vertically). Your task is to compute the area (number of cells) of the largest island in the grid. If there is no island, return 0.
Formally, if we denote the grid by , an island is a connected component of cells where . The area is simply the count of cells in that component. Use Depth-First Search (DFS) or Breadth-First Search (BFS) to solve this problem.
inputFormat
The first line of input contains two space-separated integers and , representing the number of rows and columns respectively. Each of the next lines contains space-separated integers (either 0 or 1), representing the grid.
outputFormat
Output a single integer, which is the maximum area of an island found in the grid.## sample
4 5
1 1 0 0 0
1 1 0 0 0
0 0 1 0 0
0 0 0 1 1
4