Google | Phone | Running Sum of a Matrix

Position: SDE in ML

I was asked to compute the 2D prefix sum of a given matrix

Prefix sum is defined as running sum of a given matrix.
1d prefix sum is illustrated with following example

Input: 1 2 3
Output: 1 3 6

2d prefix sum is illustrated with following example

Input
1 2 3
1 1 1
2 1 2

Output
1 3 6
2 4 6
4 6 9
Comments (11)