Place two axis-aligned squares on the grid such that:
both squares have the same side length,
every cell inside each square is 1,
the two squares do not share any cell.
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.
Examples
Example 1
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.
Example 2
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.
Constraints
1≤n,m≤700
grid[i][j] is 0 or 1
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up