The TransCompilator

Solved LeetCode program · 918 of 1,000

#1277 · Count Square Submatrices with All Ones

Medium Array chunk-19.md

Original English source

The matrix is a list of 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, and 1. The rows is 3, while the columns is 4. The table is a list of 12 zeros. The total is 0.
For every row from 0 to rows minus 1.
For every column from 0 to columns minus 1.
The index is row times columns plus column.
If item index of matrix is 1.
The above is 0. The left is 0. The corner is 0. If row is more than 0, set above to item (index minus columns) of table. If column is more than 0, set left to item (index minus 1) of table. If row is more than 0 and column is more than 0, set corner to item (index minus columns minus 1) of table. The small is the smaller of above and left. Set small to the smaller of small and corner. Set item index of table to small plus 1. Increase total by item index of table.

Show total.

Open in Playground Browse all 1,000 problems

Expected stdout

15