#K40067. Largest Land Square
Largest Land Square
Largest Land Square
You are given a grid of dimensions \(N\) rows and \(M\) columns. Each cell in the grid is either land (represented by 0) or water (represented by 1). Your task is to determine the side length of the largest square sub-grid that consists entirely of land cells (0). The sides of the square must be parallel to the grid axes.
Input Format: The first line contains two integers \(N\) and \(M\), which represent the number of rows and columns respectively. This is followed by \(N\) lines, each containing \(M\) space-separated integers representing the grid.
Output Format: Output a single integer which is the side length of the largest square containing only land cells. If no such square exists, output \(0\).
Example:
Input: 4 5 0 1 0 0 0 1 0 0 1 0 0 0 0 1 0 1 1 0 0 0</p>Output: 2
inputFormat
The input is read from stdin and has the following format:
- The first line contains two integers \(N\) and \(M\) — the numbers of rows and columns in the grid.
- The next \(N\) lines each contain \(M\) integers (either 0 or 1) separated by spaces representing the grid.
outputFormat
Print a single integer to stdout — the side length of the largest square that consists entirely of land cells (0). If there is no such square, print 0.
## sample4 5
0 1 0 0 0
1 0 0 1 0
0 0 0 1 0
1 1 0 0 0
2