#K3746. Maximum Square in a Binary Matrix
Maximum Square in a Binary Matrix
Maximum Square in a Binary Matrix
Given a binary matrix \(grid\) of size \(m \times n\) consisting of characters '0' and '1', find the area of the largest square that can be formed using only '1's.
The problem requires you to determine the maximum side length \(s\) of a square with all '1's such that its area, given by \(s^2\), is maximized.
Example:
Input: 4 5 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 0 0</p>Output: 4
Here, the largest square is of side length 2, so the area is \(2^2 = 4\).
inputFormat
The first line of input contains two integers \(m\) and \(n\), which represent the number of rows and columns of the matrix respectively.
The following \(m\) lines each contain \(n\) space-separated characters, each being either '0' or '1', representing the elements of the matrix.
You can assume that \(1 \leq m, n \leq 1000\).
outputFormat
Output a single integer that is the area of the largest square containing only '1's.
If there is no such square, output 0.
## sample4 5
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 0 0
4