Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice

What is the length of the longest palindromic subsequence (not substring) of "DDCBAEBDC"?

  1. A. 6
  2. B. 8
  3. C. 5
  4. D. 3

Correct answer: C. 5

d[i][j] = d[i+1][j−1]+2 if s[i]=s[j], else max(d[i+1][j], d[i][j−1]) → 5 (equals LCS of s and its reverse). The longest palindromic substring has length 2.

More Coding Interview Problems questions

Exams that ask this topic