Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice

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

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

Correct answer: A. 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 3.

More Coding Interview Problems questions

Exams that ask this topic