![]() |
VOOZH | about |
Given two m x n matrices m1 and m2, the task is to subtract m2 from m1 and return res.
Input: m1 = {{1, 2},
{3, 4}},
m2 = {{4, 3},
{2, 1}}
Output: {{-3, -1},
{1, 3}}
Input: m1 = {{3, 3, 3},
{3, 3, 3}},
m1 = {{2, 2, 2},
{1, 1, 1}},
Output: {{1, 1, 1},
{2, 2, 2}},
We traverse both matrices element by element and subtract m2[i][j] from m1[i][j].
Result matrix is: 0 1 2 3 4 5
Time complexity: O(n2)