#K72322. Counting Land Areas
Counting Land Areas
Counting Land Areas
You are given a 2D map composed of characters 'L' and 'W' representing land and water respectively. A land area is defined as a group of horizontally or vertically adjacent cells that contain the character 'L'. Your task is to count the number of distinct land areas in the map.
The map is given as n rows and m columns. Cells connected diagonally are not considered adjacent. In mathematical terms, if we denote the grid as \( A_{i,j} \), then two cells \( A_{i,j} \) and \( A_{k,l} \) are connected if and only if \(|i-k|+|j-l|=1\) and both have the value 'L'.
Example
Input: 4 5 LLWWW LLWWL LWWLW WWWLL</p>Output: 3
inputFormat
The first line contains two integers n and m indicating the number of rows and columns of the map, respectively.
Then follow n lines, each containing a string of length m made up of the characters 'L' (land) and 'W' (water).
outputFormat
Output a single integer representing the number of distinct land areas in the given map.
## sample4 5
LLWWW
LLWWL
LWWLW
WWWLL
3