Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the DP array for unique paths.
DSA Java
int[][] dp = new int[m][[1]];Attempts:
3 left
💡 Hint
Common Mistakes
Using m for both dimensions causes incorrect array size.
Using 1 or 0 as dimension leads to runtime errors.
✗ Incorrect
The DP array should have dimensions m rows and n columns to match the grid size.
2fill in blank
mediumComplete the code to set the base case for the first row in the DP array.
DSA Java
for (int j = 0; j < n; j++) { dp[0][j] = [1]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting dp[0][j] to 0 means no paths are counted.
Using j or m as value is incorrect for base case.
✗ Incorrect
There is exactly 1 way to reach any cell in the first row by moving right only.
3fill in blank
hardFix the error in the nested loop to compute unique paths.
DSA Java
for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { dp[i][j] = dp[i - 1][j] [1] dp[i][j - 1]; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication leads to wrong path counts.
Division is invalid in this context.
✗ 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 method signature and return statement.
DSA Java
public int [1](int m, int n) { int[][] dp = new int[m][n]; // initialization code return [2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Returning dp[0][0] returns the start cell, not the result.
Using incorrect method names causes confusion.
✗ Incorrect
The method name is uniquePaths and it returns the bottom-right cell value dp[m-1][n-1].
5fill in blank
hardFill all three blanks to complete the DP initialization for first column and first row.
DSA Java
for (int i = 0; i < m; i++) { dp[i][0] = [1]; } for (int j = 0; j < n; j++) { dp[0][j] = [2]; } for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { dp[i][j] = dp[i - 1][j] [3] dp[i][j - 1]; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting base cells to 0 means no paths counted.
Using subtraction instead of addition breaks logic.
✗ Incorrect
First column and row cells have 1 path each; inner cells sum paths from top and left.
