Company: Mathworks IIT Bhubaneswar
Difficulty: medium
Simple Matrix Summation Problem Description Given an n x m matrix a , create another n x m matrix b using a summation algorithm. For each element b(x, y) in matrix b , the value is determined by the following algorithm: s = 0; for (i = 0; i <= x; i++) { for (j = 0; j <= y; j++) { s = s + a(i, j); } } b(x, y) = s; The algorithm must be executed for each element of matrix b . Return the completed matrix b . Complete the function findMatrix in the editor with the following parameter(s): int a[n][m] : a 2-dimensional array of integers Examples Example 1: Input: a = [[1, 2, 3], [4, 5, 6]] Output: [[1, 3, 6], [5, 12, 21]] Explanation: Given the input matrix a : 1 2 3 4 5 6 The calculations for matrix b are as follows: b(0,0) = a(0,0) = 1 b(0,1) = a(0,0) + a(0,1) = 1 + 2 = 3 b(0,2) = a(0,0) + a(0,1) + a(0,2) = 1 + 2 + 3 = 6 b(1,0) = a(0,0) + a(1,0) = 1 + 4 = 5 b(1,1) = a(0,0) + a(0,1) + a(1,0) + a(1,1) = 1 + 2 + 4 + 5 = 12 b(1,2) = a(0,0) + a(0,1) + a(0,2) + a(1,0) + a(1,1) + a(1,2) = 1