![]() |
VOOZH | about |
Given two N x M matrices. Find a N x M matrix as the sum of given matrices each value at the sum of values of corresponding elements of the given two matrices.
Approach: Below is the idea to solve the problem.
Iterate over every cell of matrix (i, j), add the corresponding values of the two matrices and store in a single matrix i.e. the resultant matrix.
Follow the below steps to Implement the idea:
Below is the Implementation of above approach.
Result matrix is 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8
Time complexity: O(n x m).
Auxiliary space: O(n x m). since n2 extra space has been taken for storing results
The program can be extended for rectangular matrices. The following post can be useful for extending this program.