[InterviewBit] Grid Unique Paths

Grid Unique Paths

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
int Solution::uniquePaths(int A, int B) {
vector<int> dp(B);
dp[0] = 1;
for(int i = 0; i < A; i++) {
for(int j = 0; j < B; j++) {
dp[j] = (j ? dp[j-1] : 0) + dp[j];
}
}
return dp[B-1];
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/09/21/PS/interviewbit/grid-unique-paths/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.