Problem Brief
Generate Matrix B
OA
You are given a 2d matrix A of m rows and n columns and you have to generate a matrix B of same dimension but the elements must be a summation of all the previous elements up to now.
Function Description
Complete the function generateMatrixB in the editor.
generateMatrixB has the following parameter:
int[][] A: a 2D array of integers
Returns
int[][]: the generated matrix B
1Example 1
Input
A = [[1,2,3],[4,5,6]]
Output
[[1,3,6],[5,12,21]]
Explanation
The elements of matrix B are calculated as follows:
B(0,0) = A(0,0) = 1B(0,1) = A(0,0) + A(0,1) = 1 + 2 = 3B(0,2) = A(0,0) + A(0,1) + A(0,2) = 1 + 2 + 3 = 6B(1,0) = A(0,0) + A(1,0) = 1 + 4 = 5B(1,1) = A(0,0) + A(0,1) + A(1,0) + A(1,1) = 1 + 2 + 4 + 5 = 12B(1,2) = A(0,0) + A(0,1) + A(0,2) + A(1,0) + A(1,1) + A(1,2) = 1 + 2 + 3 + 4 + 5 + 6 = 21
Constraints
Limits and guarantees your solution can rely on.
๐๐