solulubeta
Sign in
Recursion & Memo / DP patterns for coding tests
04.10 · Lesson

Two Strings: LCS and Edit Distance

One pointer in each string. If the characters match, move both. If not, try each allowed move and keep the best. Covers longest common subsequence and edit distance.

9 min 2 videos Quiz Pro

When a question gives you two strings, the state is a position in each:

f(i, j) = the answer for a[i..] and b[j..]
  • Characters match: use them and move both pointers.
  • They don’t match: try each allowed move and keep the best.
  • Base case: one string is used up.
solulu Pro

Continue this lesson with Pro

Inside: 4 sections · 2 videos · quiz.

  • Try it before reading on
  • Longest common subsequence (LCS)
  • Edit distance
  • Related questions
Lifetime ₹1,999 ₹999 · Launch offer
Mark this as done when you are finished.

Item 36 of 44 · updated 2026-10-13