grid and a number goal. A rectangle is a non-empty block of cells bounded by rows r1 to r2 and columns c1 to c2, inclusive.
Return how many rectangles have cells summing to goal. Two rectangles are different if at least one of their borders differs.grid=[[0, 3], [-3, 0]], goal=0 → 3
The two zero cells and the whole table (0 + 3 - 3 + 0 = 0) sum to 0; every row and column sums to 3 or -3.
grid=[[1, 1, 1]], goal=2 → 2
Two 1×2 rectangles sum to 2: the first two cells and the last two.
grid=[[5]], goal=-5 → 0
grid), len(grid[0]) ≤ 150grid have the same lengthgrid[i][j] ≤ 1000goal ≤ 10⁸grid=[[0, 3], [-3, 0]], goal=0
3
Run checks the first 3 tests in your browser. Submit checks all 85 tests on the server, hidden ones included.