Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice

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

  1. A. 12
  2. B. 6
  3. C. 5
  4. D. 9

Correct answer: B. 6

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

More Coding Interview Problems questions

Exams that ask this topic