grid of zeros and ones. Return how many square submatrices of any size consist entirely of 1s.
Squares of different sizes or positions are counted separately, even when they overlap.grid=[[1, 1, 0], [1, 1, 1], [0, 1, 1]] → 9
There are 7 squares of side 1 and two all-ones 2 × 2 squares, in the top-left and bottom-right corners: 9 in total.
grid=[[1, 0, 1, 1]] → 3
A single row only fits 1 × 1 squares, one for each 1.
grid=[[1, 1, 1], [1, 1, 1], [1, 1, 1]] → 14
grid=[[1, 1, 0], [1, 1, 1], [0, 1, 1]]
9
Run checks the first 3 tests in your browser. Submit checks all 70 tests on the server, hidden ones included.