The TransCompilator

Solved LeetCode program · 820 of 1,000

#1074 · Number of Submatrices That Sum to Target

Hard Array chunk-17.md

Original English source

The grid is a list of 0, 1, 0, 1, 1, 1, 0, 1, and 0. The rows is 3. The columns is 3. The width is 4. The target is 0. The prefix is a list of 16 zeros.
For every row from 0 to rows minus 1.
For every column from 0 to columns minus 1.
The index is (row plus 1) times width plus column plus 1. The above is index minus width. The before is index minus 1. The corner is index minus width minus 1. The cell is item (row times columns plus column) of grid. Set item index of prefix to item above of prefix plus item before of prefix minus item corner of prefix plus cell.

The total is 0.
For every top from 0 to rows minus 1.
For every bottom from top to rows minus 1.
For every left from 0 to columns minus 1.
For every right from left to columns minus 1.
The bottomright is (bottom plus 1) times width plus right plus 1. The topright is top times width plus right plus 1. The bottomleft is (bottom plus 1) times width plus left. The topleft is top times width plus left. The measured is item bottomright of prefix minus item topright of prefix minus item bottomleft of prefix plus item topleft of prefix. If measured is target, add 1 to total.

Show total.

Open in Playground Browse all 1,000 problems

Expected stdout

4