prefixSum
with the same dimensions as mat
, plus one extra row and column filled with zeros.prefixSum
by calculating the cumulative sum for each cell based on the values to the left, above, and diagonally above-left.answer
with the same dimensions as mat
.mat
.answer
.answer
matrix.