FunctionRacerProblemsRace

Blocks That Add Up

HardHash mapsPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems