Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the 2D slice for dynamic programming.
DSA Go
dp := make([][]int, len(s1)+1) for i := range dp { dp[i] = make([]int, [1]) }
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(s1)+1 for inner slice length causes index errors.
Forgetting the +1 for empty string cases.
✗ Incorrect
The dp table needs to have rows for each character in s1 plus one, and columns for each character in s2 plus one. So each row slice length is len(s2)+1.
2fill in blank
mediumComplete the code to fill the first row of the dp table.
DSA Go
for j := 0; j <= len(s2); j++ { dp[0][j] = [1] }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting dp[0][j] to 0 causes wrong base case.
Using len(s2) instead of j.
✗ Incorrect
The first row represents converting empty s1 to first j characters of s2, so cost is j insertions.
3fill in blank
hardFix the error in the condition to check if characters are equal.
DSA Go
if s1[i-1] [1] s2[j-1] { dp[i][j] = dp[i-1][j-1] } else { dp[i][j] = min(dp[i-1][j]+1, dp[i][j-1]+1, dp[i-1][j-1]+1) }
Attempts:
3 left
💡 Hint
Common Mistakes
Using single '=' causes syntax error.
Using '!=' reverses logic.
✗ Incorrect
To check if characters are equal, use '=='. Using '=' is assignment and causes error.
4fill in blank
hardFill both blanks to complete the min function call for edit operations.
DSA Go
dp[i][j] = min(dp[i-1][j][1]1, dp[i][j-1][2]1, dp[i-1][j-1]+1)
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' subtracts cost incorrectly.
Using '*' or '/' causes wrong calculations.
✗ Incorrect
We add 1 to each operation cost: deletion dp[i-1][j]+1 and insertion dp[i][j-1]+1.
5fill in blank
hardFill all three blanks to complete the min function that returns the smallest of three integers.
DSA Go
func min(a, b, c int) int { if a [1] b && a [2] c { return a } else if b [3] c { return b } return c }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' returns maximum instead of minimum.
Using '>=' or '<=' can cause incorrect ties.
✗ Incorrect
To find minimum, check if a < b and a < c, else if b < c, else c is smallest.
