forked from royalpranjal/Interview-Bit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniquePathsInAGrid.cpp
More file actions
25 lines (20 loc) · 826 Bytes
/
Copy pathUniquePathsInAGrid.cpp
File metadata and controls
25 lines (20 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// https://www.interviewbit.com/problems/unique-paths-in-a-grid/
int paths(vector<vector<int> > A, int currX, int currY, int maxX, int maxY){
if(currX >= maxX || currY >= maxY){
return 0;
}
else if(A[currX][currY] == 1){
return 0;
}
else if(currX == maxX-1 && currY == maxY-1){
return 1;
}
return paths(A, currX + 1, currY, maxX, maxY) + paths(A, currX, currY + 1, maxX, maxY);
}
int Solution::uniquePathsWithObstacles(vector<vector<int> > &A) {
// Do not write main() function.
// Do not read input, instead use the arguments to the function.
// Do not print the output, instead return values as specified
// Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details
return paths(A, 0, 0, A.size(), A[0].size());
}