Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the DP table with 1 for the first row.
DSA C++
for (int j = 0; j < n; j++) dp[0][j] = [1];
Attempts:
3 left
💡 Hint
Common Mistakes
Setting dp[0][j] to 0 instead of 1.
Using the wrong index or variable.
✗ Incorrect
The first row has only one way to reach each cell by moving right, so dp[0][j] = 1.
2fill in blank
mediumComplete the code to initialize the DP table with 1 for the first column.
DSA C++
for (int i = 0; i < m; i++) dp[i][0] = [1];
Attempts:
3 left
💡 Hint
Common Mistakes
Setting dp[i][0] to 0 instead of 1.
Using the wrong variable or index.
✗ Incorrect
The first column has only one way to reach each cell by moving down, so dp[i][0] = 1.
3fill in blank
hardFix the error in the DP update step to correctly calculate unique paths.
DSA C++
dp[i][j] = dp[i - 1][j] [1] dp[i][j - 1];
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Confusing the order of operands.
✗ Incorrect
The number of ways to reach dp[i][j] is the sum of ways from the top and left cells.
4fill in blank
hardFill both blanks to complete the nested loops for DP table filling.
DSA C++
for (int i = 1; i [1] m; i++) { for (int j = 1; j [2] n; j++) { dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causing index out of range.
Using '>' or '>=' causing loops not to run.
✗ Incorrect
Loops run from 1 up to but not including m and n, so use '<' operator.
5fill in blank
hardFill all three blanks to complete the function returning unique paths count.
DSA C++
int uniquePaths(int m, int n) {
vector<vector<int>> dp(m, vector<int>(n, 0));
for (int i = 0; i [1] m; i++) dp[i][0] = 1;
for (int j = 0; j [2] n; j++) dp[0][j] = 1;
for (int i = 1; i [3] m; i++) {
for (int j = 1; j < n; j++) {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
return dp[m - 1][n - 1];
}Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causing out-of-bound access.
Using '==' or '>' causing loops not to run properly.
✗ Incorrect
All loops run with '<' to avoid out-of-bound errors and cover all indices.
