Blocks That Add Up
A block is a rectangle of cells of grid: every cell from one row to another and from one column to another. A single cell is a block too.
Return how many blocks have cells that add up to target. Blocks at different places count separately.
Example 1
grid [[2,1],[1,2]]
target 3
returns 4
Both rows and both columns add up to 3. No single cell does, and the whole grid adds up to 6.
Example 2
grid [[0,0]]
target 0
returns 3
Each cell alone is 0, and so are the two cells together.
Constraints
1 <= len(grid) <= 121 <= len(grid[0]) <= 12, and every row has that length-100 <= grid[r][c] <= 100-104 <= target <= 104
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.