Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the DP table with zeros.
DSA Go
dp := make([][]int, m) for i := 0; i < m; i++ { dp[i] = make([]int, [1]) }
Attempts:
3 left
💡 Hint
Common Mistakes
Using m instead of n for the inner slice length.
Initializing dp with zero length slices.
✗ Incorrect
The DP table has m rows and n columns, so each row slice should have length n.
2fill in blank
mediumComplete the code to set the number of ways to reach the first cell.
DSA Go
dp[0][0] = [1]
Attempts:
3 left
💡 Hint
Common Mistakes
Setting dp[0][0] to 0, which means no paths start there.
Using negative or invalid values.
✗ Incorrect
There is exactly one way to stand at the starting cell: start there.
3fill in blank
hardFix the error in the nested loops to correctly fill the DP table.
DSA Go
for i := 0; i < m; i++ { for j := 0; j < [1]; j++ { if i == 0 && j == 0 { continue } up := 0 left := 0 if i > 0 { up = dp[i-1][j] } if j > 0 { left = dp[i][j-1] } dp[i][j] = up + left } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using m for both loops causing index errors.
Using loop variables incorrectly.
✗ Incorrect
The inner loop should run over columns, which is n.
4fill in blank
hardFill both blanks to return the total unique paths from top-left to bottom-right.
DSA Go
return dp[[1]-1][[2]-1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 1 instead of m-1 or n-1.
Mixing up row and column indices.
✗ Incorrect
The bottom-right cell is at row m-1 and column n-1.
5fill in blank
hardFill all three blanks to create a map of unique paths for each cell with conditions.
DSA Go
for i := 0; i < m; i++ { for j := 0; j < n; j++ { if i == 0 && j == 0 { dp[i][j] = [1] } else { up := 0 left := 0 if i > 0 { up = dp[i-1][j] } if j > 0 { left = dp[i][j-1] } dp[i][j] = up [2] left } } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Setting start cell to 0.
✗ Incorrect
Start cell has 1 path; each cell sums paths from above and left.
