#K80972. Largest Island Size
Largest Island Size
Largest Island Size
You are given a 2D grid of characters, where each cell is either 'L' (land) or 'W' (water). An island is a group of adjacent land cells connected horizontally or vertically (note that diagonal connections do not count). The task is to determine the size of the largest island in the grid.
The input starts with two integers \(M\) and \(N\) on the first line representing the number of rows and columns respectively. Each of the next \(M\) lines contains a string of length \(N\) consisting of characters 'L' or 'W'.
The output is a single integer showing the maximum number of connected 'L's, which is the size of the largest island. If there is no island, output 0.
Note: Connections are only considered vertically and horizontally.
inputFormat
The first line contains two integers \(M\) and \(N\), where \(M\) is the number of rows and \(N\) is the number of columns.
The next \(M\) lines each contain a string of exactly \(N\) characters, each either 'L' (land) or 'W' (water).
This input is provided via standard input (stdin).
outputFormat
Output a single integer representing the size of the largest island found in the grid. The output should be written to standard output (stdout).
## sample4 5
LWLWL
WWWLL
LLLWW
LWLWL
5