left
and top
of the same dimensions as the input grid to store the number of consecutive 1
s to the left and above each cell, respectively.left
and top
arrays by iterating over the grid and updating the count of consecutive 1
s.maxSquare
to keep track of the size of the largest square found so far.left
and top
arrays.1
s.maxSquare
if the found square is larger than the current maxSquare
.maxSquare * maxSquare
as the area of the largest square with 1
s on its border.