Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the DP table with zeros.
DSA Python
dp = [[0 for _ in range(n+1)] for _ in range([1]+1)]
Attempts:
3 left
💡 Hint
Common Mistakes
Using the length of the second sequence instead of the first.
Forgetting to add 1 for the base case row.
✗ Incorrect
The DP table size depends on the length of the first sequence, usually denoted as 'm'.
2fill in blank
mediumComplete the code to fill the DP table by comparing characters of two strings.
DSA Python
if s1[i-1] == s2[[1]-1]:
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable for the second string index.
Not subtracting 1 from the index.
✗ Incorrect
We compare the character at position i-1 in s1 with the character at position j-1 in s2.
3fill in blank
hardFix the error in updating the DP table when characters match.
DSA Python
dp[i][j] = dp[i-1][j-1] [1] 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to add 1.
✗ Incorrect
When characters match, we add 1 to the diagonal value in the DP table.
4fill in blank
hardFill both blanks to update the DP table when characters do not match.
DSA Python
dp[i][j] = max(dp[i-[1]][j], dp[i][j-[2]])
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong numbers like 0 or 2 for the steps back.
Using variable names instead of numbers.
✗ Incorrect
We look one step back in both sequences to find the maximum value.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps each word to its length if length is greater than 3.
DSA Python
{ [1]: [2] for [3] in words if len([3]) > 3 }Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Mapping keys to wrong values.
✗ Incorrect
We use 'word' as the variable, map it to its length, and iterate over 'words'.
