Problem Details
Print All Possible Paths From Top Left Corner To Bottom Right Corner Of A 2-D Matrix



1 2 3
4 5 6
For the above 2*3 matrix , possible paths are (1 2 3 6) , (1 2 5 6) , (1 4 5 6).
You can return the paths in any order.
The first line contains two space-separated integers, ‘M’ and ‘N’ denoting the number of rows and columns of the given matrix.
Each of the following ‘M’ lines contains N space-separated numbers.
Print all the paths in a new line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= M, N <= 10
Time Limit: 1 sec
The basic idea to solve this problem is to use recursion. Recursively call function for next row ( row+1,col ) and next column ( row, col+1 ). If the row is equal to M-1 or the column is equal to N-1, then recursion is stopped.
Algorithm:
Let us understand the above approach with the help of a recursion tree for the matrix given below
1 2 3
4 5 6
Output: 1 4 5 6
1 2 5 6
1 2 3 6