Back to problems

Compute Every Fixed-Size Submatrix Sum

Algorithm · Citadel · Medium

Given a rectangular integer matrix matrix and an integer k, create a new matrix result such that result[r][c] equals the sum of all entries in the square block of side length k whose upper-left cell is matrix[r][c]. A valid block must fit completely inside matrix, so r ranges from 0 to rows - k and c ranges from 0 to columns - k. Implement k_by_k_sums(matrix, k) -> list[list[int]]. Do not mutate matrix; return a separate list-of-lists. When k = 1, the returned matrix…

Checking your access…