#K36852. Largest Connected Component
Largest Connected Component
Largest Connected Component
You are given a grid of size \(R \times C\). Each cell of the grid is assigned an integer value representing its altitude. Two cells are considered connected if they share a side (up, down, left, or right) and have the same altitude. Your task is to determine the size of the largest connected component in the grid.
Input: The first line contains two integers \(R\) and \(C\), representing the number of rows and columns, respectively. This is followed by \(R\) lines each containing \(C\) space-separated integers representing the grid.
Output: Print a single integer: the size of the largest connected component.
Example:
Input: 4 5 1 1 0 2 2 3 1 1 2 2 4 4 1 1 0 4 4 4 4 0</p>Output: 6
inputFormat
The first line of input contains two space-separated integers \(R\) and \(C\). Each of the next \(R\) lines contains \(C\) space-separated integers, where each integer represents the altitude of a cell in the grid.
outputFormat
Output a single integer representing the size of the largest connected component in the grid.
## sample4 5
1 1 0 2 2
3 1 1 2 2
4 4 1 1 0
4 4 4 4 0
6
</p>