Back to problems

Generate Matrix B

Algorithm · Arista · Medium

You are given a 2‑D integer matrix A with dimensions m rows and n columns. Construct a new matrix B of the same size where each entry B[i][j] is defined as the sum of all elements in A that lie in the rectangular region from the top‑left corner (0,0) down to the cell (i,j), inclusive. In other words: B[i][j] = sum_{p=0..i, q=0..j} A[p][q] Return the matrix B. This kind of cumulative grid computation comes up frequently in data analytics and applications that process 2‑D…

Loading the rest of the question…