#K47962. Largest Square Block
Largest Square Block
Largest Square Block
You are given an N × N grid representing a city layout. Each cell in the grid is either a building (denoted by 1) or an open plot (denoted by 0). You have the power to convert any open plot into a building.
Your task is to determine the side length of the largest square block (i.e. a contiguous square subgrid) of buildings that can be formed after optimally converting the open plots to buildings. Since you can convert any open plot, the optimal strategy is to convert every cell, which means the maximum square block you can obtain is the entire grid itself. In other words, the answer for each test case is equal to N, the dimension of the grid.
Formally, if you are given a grid of size N × N, the maximum possible side length of a square block comprising only buildings is:
\[ \text{max side length} = N \]
Note that although the grid values are provided as input, they do not affect the answer.
inputFormat
The first line contains an integer T, the number of test cases.
For each test case, the first line contains an integer N representing the size of the grid. This is followed by N lines, each containing N integers (0 or 1) separated by spaces, representing the grid.
Input is read from stdin.
outputFormat
For each test case, output a single integer representing the side length of the largest square block of buildings that can be formed. Output each result on a new line.
Output is written to stdout.
## sample2
3
1 0 1
0 1 0
1 0 1
4
0 1 1 0
1 0 1 1
1 1 0 0
0 0 1 1
3
4
</p>