Skip to content

Commit

Permalink
Merge pull request #399 from RuhiRaj/main
Browse files Browse the repository at this point in the history
Create GridPath.cpp
  • Loading branch information
MSubhajitIND authored Oct 16, 2023
2 parents a218de5 + 075b101 commit 5dce494
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions GridPath.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
int mazeObstacles(int n, int m, vector< vector< int> > &mat) {
int dp[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if (mat[i][j] == -1) {
dp[i][j] = 0;
} else if (i == 0 && j == 0) {
dp[i][j] = 1;
} else {
int left = 0, up = 0;
if (j > 0)
left = dp[i][j - 1];
if (i > 0)
up = dp[i - 1][j];
dp[i][j] = (left + up)%(int)(1e9+7);
}
}
}
return dp[n-1][m-1];
}

0 comments on commit 5dce494

Please sign in to comment.