Skip to content

added advance question that used dynamic programming #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Advance.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1092,4 +1092,30 @@ solution: -----python-----

print (out_)

17) There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any point in time.

Given the two integers m and n, return the number of possible unique paths that the robot can take to reach the bottom-right corner.

solution : -------Java-------

class Solution {
public int findPath(int i,int j, int m,int n,int[][] dp){
if(i==(n-1) && j==(m-1)) return 1;
if(i>=n || j>=m) return 0;
if(dp[i][j]!=-1)return dp[i][j];
return dp[i][j]=findPath(i,j+1,m,n,dp)+findPath(i+1,j,m,n,dp);
}
public int uniquePaths(int m, int n) {
int[][] dp = new int[n][m];
for(int[] row : dp){
Arrays.fill(row,-1);
}
return findPath(0,0,m,n,dp);
}
public static void main(String[] args) {
int m = 3;
int n = 7;
System.out.println(uniquePaths(m,n));
}
}