0
0
DSA Typescriptprogramming~10 mins

Longest Common Subsequence in DSA Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the 2D array for dynamic programming.

DSA Typescript
const dp: number[][] = Array(m + 1).fill(null).map(() => Array([1]).fill(0));
Drag options to blanks, or click blank then click option'
Am + 1
Bn + 1
Cn
Dm
Attempts:
3 left
💡 Hint
Common Mistakes
Using m instead of n for the inner array size.
Not adding 1 to the lengths for dp array size.
2fill in blank
medium

Complete the code to check if characters match at current indices.

DSA Typescript
if (text1[i - 1] [1] text2[j - 1]) {
Drag options to blanks, or click blank then click option'
A==
B!=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using inequality instead of equality.
Using greater than or less than operators.
3fill in blank
hard

Fix the error in updating dp when characters do not match.

DSA Typescript
dp[i][j] = Math.max(dp[i - 1][j], dp[i][[1]]);
Drag options to blanks, or click blank then click option'
Aj - 1
Bi - 1
Cj + 1
Di + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using i-1 instead of j-1 for the second index.
Using j+1 or i+1 which goes out of bounds.
4fill in blank
hard

Fill both blanks to complete the nested loops iterating over dp table.

DSA Typescript
for (let i = 1; i [1] m + 1; i++) {
  for (let j = 1; j [2] n + 1; j++) {
Drag options to blanks, or click blank then click option'
A<
B<=
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes index out of bounds.
Using > or >= reverses loop logic.
5fill in blank
hard

Fill all three blanks to return the final LCS length from dp table.

DSA Typescript
return dp[1][2][3];
Drag options to blanks, or click blank then click option'
A[m]
B[n]
C[n][m]
D[m][n]
Attempts:
3 left
💡 Hint
Common Mistakes
Using dp[n][m] which swaps indices.
Using dp[m] or dp[n] which returns a row or column, not a single value.