⭐Grid Unique Paths
Using DFS (very bad time complexity)
int res = 0;
void getWays(int i, int j, int m, int n) {
if(i == m && j == n) {
res++;
return;
}
// right
if(m > i)
getWays(i, j + 1, m, n);
// down
if(n > j)
getWays(i + 1, j, m, n);
}
int Solution::uniquePaths(int A, int B) {
getWays(0, 0, A, B);
return res;
}
Using Combination (Optimal)
Last updated