Loading...
You are given an n x m grid of 0s and 1s.
Place two axis-aligned squares on the grid such that:
1,A single cell (1 x 1) counts as a valid square.
Return the maximum possible side length of such a pair of squares, or 0 if no valid pair exists.
Input: grid = [[1,1,0],
[1,1,1],
[0,1,1]]
Output: 1
Explanation: There are 2 x 2 all-1 squares (top-left and bottom-right), but any
two of them share the center cell. Two disjoint 1 x 1 squares exist, so the
answer is 1.
Input: grid = [[1,1,1,1],
[1,1,1,1]]
Output: 2
Explanation: The left 2 x 2 square (columns 0-1) and the right 2 x 2 square
(columns 2-3) are both all-1 and disjoint.
grid[i][j] is 0 or 1Click "Run" to test with sample cases or "Submit" to run all tests.