Learn
Practice
Newsletter
Resources
Animations
New
F
Toggle theme
0
F
0
Toggle menu
← Back to All Animations
Count Square Submatrices with All Ones
Bookmark
Input
Example 1
Example 2
Example 3
Custom
matrix
=
[[0,1,1,1],[1,1,1,1],[0,1,1,1]]
3x4
count =
0
0
1
1
1
1
1
1
1
0
1
1
1
each 1 counts the squares ending at it; the answer is the sum
algo
master
.
io
Step:
Count every all-1s square. Each 1 answers: how many squares END at me? Sum the answers
0 / 16
Input
Example 1
Example 2
Example 3
Custom
matrix
=
[[0,1,1,1],[1,1,1,1],[0,1,1,1]]
0 / 16
3x4
count =
0
0
1
1
1
1
1
1
1
0
1
1
1
each 1 counts the squares ending at it; the answer is the sum
algo
master
.
io
Step:
Count every all-1s square. Each 1 answers: how many squares END at me? Sum the answers