grid of 0s and 1s.
Find the largest square whose border cells are all 1s (what is inside does not matter). Return the number of cells in that square, that is, its side length squared. If the table has no 1s at all, return 0.
A single cell holding 1 counts as a square of side 1.grid=[[1, 1, 1, 0], [1, 0, 1, 1], [1, 1, 1, 1]] → 9
The 3 × 3 frame in the top-left corner is all 1s (the 0 inside does not matter), so it covers 9 cells.
grid=[[0, 1], [1, 1]] → 1
A 2 × 2 square fails because of the 0 in the corner. Any single 1 works, giving 1 cell.
grid=[[0, 0, 0]] → 0
There are no 1s at all, so the answer is 0.
grid=[[1, 1, 1, 0], [1, 0, 1, 1], [1, 1, 1, 1]]
9
Run checks the first 3 tests in your browser. Submit checks all 67 tests on the server, hidden ones included.