A survey drone scans a rectangular plot of land represented as a grid with rows rows and cols columns. Each tile is either clear (1) or obstructed (0). Find the area (side length squared) of the largest square sub-grid, aligned to the grid axes, whose tiles are all clear.
Line 1: two integers rows and cols.
Each of the next rows lines: cols space-separated integers, each 0 (obstructed) or 1 (clear).
A single integer: the area of the largest all-clear square sub-grid. If there is no clear tile at all, print 0.
0 or 1Example 1
Input
4 4 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 1
Expected
9
Explanation
The 3x3 block of 1s in the top-left three rows and columns is the largest all-clear square (side 3), giving area 9.
Example 2
Input
2 3 0 0 0 0 0 0
Expected
0
Explanation
There is no clear tile anywhere, so the largest all-clear square has area 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →