Tap here to switch tabs
Problem
Submissions

Problem: Matrix Block Sum

med
30 min
Try to solve the Matrix Block Sum problem.

Statement

Given an m ×\times n integer matrix mat and an integer k, return a matrix answer of size m ×\times n where each cell answer[i][j] is the sum of all elements mat[r][c] that satisfy:

  • i−k≤r≤i+ki - k \leq r \leq i + k

  • j−k≤c≤j+kj - k \leq c \leq j + k

  • 0≤r<0 \leq r < m

  • 0≤c<0 \leq c < n

Constraints:

  • m == mat.length

  • n == mat[i].length

  • 1≤1 \leq m, n, k ≤100\leq 100

  • 1≤1 \leq mat[i][j] ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Matrix Block Sum

med
30 min
Try to solve the Matrix Block Sum problem.

Statement

Given an m ×\times n integer matrix mat and an integer k, return a matrix answer of size m ×\times n where each cell answer[i][j] is the sum of all elements mat[r][c] that satisfy:

  • i−k≤r≤i+ki - k \leq r \leq i + k

  • j−k≤c≤j+kj - k \leq c \leq j + k

  • 0≤r<0 \leq r < m

  • 0≤c<0 \leq c < n

Constraints:

  • m == mat.length

  • n == mat[i].length

  • 1≤1 \leq m, n, k ≤100\leq 100

  • 1≤1 \leq mat[i][j] ≤100\leq 100