#K51497. Largest Uniform Square Subgrid
Largest Uniform Square Subgrid
Largest Uniform Square Subgrid
You are given a grid of integers with n rows and m columns that represents a field of plants. Your task is to determine the side length of the largest square subgrid in which all cells have the same value. A square subgrid is defined as a contiguous block of cells forming a square. Note that even a single cell (i.e. a 1×1 subgrid) is considered uniform.
Formally, let \( n \) and \( m \) be the number of rows and columns respectively. You are required to find the maximum side length \( k \) (with \( 1 \le k \le \min(n, m) \)) such that there exists a square subgrid of size \( k \times k \) in which every cell in that subgrid has the same integer.
inputFormat
The input is given via standard input. The first line contains two integers n and m separated by a space, indicating the number of rows and columns respectively. This is followed by n lines, each containing m integers separated by spaces, representing the grid.
outputFormat
Output a single integer, which is the maximum side length of a square subgrid where all cells have the same value.
## sample4 5
1 2 2 3 4
2 1 1 1 5
2 1 1 1 1
3 3 3 3 3
2