Total unique paths
You are present at point ‘A’ which is the top-left cell of an M X N matrix, your destination is point ‘B’, which is the bottom-right cell of the same matrix. Your task is to find the total number of unique paths from point ‘A’ to point ‘B’.In other words, you will be given the dimensions of the matrix as integers ‘M’ and ‘N’, your task is to find the total number of unique paths from the cell MATRIX[0][0] to MATRIX['M' - 1]['N' - 1].
To traverse in the matrix, you can either move Right or Down at each step. For example in a given point MATRIX[i] [j], you can move to either MATRIX[i + 1][j] or MATRIX[i][j + 1].
Input Format:
The first line of input contains an integer 'T' representing the number of the test case.
The first and the only line of each test case contains two space-separated integers ‘M’ and ‘N’, denoting the number of rows and number of columns of the matrix respectively.
Output Format:
For every test case, return a single integer, which is the total number of unique paths for traveling from top-left to bottom-right cells of the matrix.
The output of each test case is printed in a separate line.
Note:
You don’t have to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 ≤ T ≤ 100
1 ≤ M ≤ 15
1 ≤ N ≤ 15
Where ‘M’ is the number of rows and ‘N’ is the number of columns in the matrix.
Time limit: 1 sec
CodingNinjas
author
2y
Recursive Approach
We can easily count the total number of paths by making a recursive algorithm.
The steps are as follows:
- We are given a function UNIQUEPATHS(), which takes two integers ‘M’ and ‘N’ a...read more
CodingNinjas
author
2y
Memoization
Our last approach was very simple and easy, but it’s time complexity was of exponential order. We can improve our solution by taking care of the overlapping subproblems. Thus, in this appr...read more
CodingNinjas
author
2y
Dynamic Programming
As we already know that we can improve our solution by taking care of the overlapping subproblems. Also, we can obtain the optimal solution of the problem by using the optimal solut...read more
CodingNinjas
author
2y
Dynamic Programming Space optimized
The previous approach improved our solution to a large extent by avoiding the common subproblem recomputations. But the space complexity can be even further improved...read more
Add answer anonymously...
Top Atlassian Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Atlassian Software Developer Intern
>
Atlassian Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app