🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: DP on Grids and Strings: all 10 questions

Quiz: DP on Grids and Strings · Question 3 of 10

In LCS, what happens when a[i − 1] equals b[j − 1]?

In LCS, what happens when a[i − 1] equals b[j − 1]?

  1. A.dp[i][j] = max(dp[i − 1][j], dp[i][j − 1])
  2. B.dp[i][j] = dp[i − 1][j − 1] + 1
  3. C.dp[i][j] = 0
  4. D.dp[i][j] = dp[i − 1][j] + 1
Answer & explanation

Correct answer: dp[i][j] = dp[i − 1][j − 1] + 1

The matching letter extends the best common subsequence of the two shorter prefixes.

Can you get the rest right without peeking?

Take the timed Quiz: DP on Grids and Strings quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →