![]() |
VOOZH | about |
Given a matrixmat[][] of size n x m, the task is to traverse this matrix using recursion.
Examples:
Input: mat[][] = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
Output: 1 2 3 4 5 6 7 8 9
Input: mat[][] = [[11, 12, 13],
[14, 15, 16],
[17, 18, 19]]
Output: 11 12 13 14 15 16 17 18 19
Approach:
Below is the implementation of the above approach:
1 2 3 4 5 6 7 8 9
Time Complexity: O(N * M)
Auxiliary Space: O(M), because of recursive calling