GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The longest palindromic subsequence of the string BCABDACBDCA has length:

  1. A. 7
  2. B. 6
  3. C. 8
  4. D. 9

Correct answer: A. 7

The DP L[i][j] = L[i+1][j−1] + 2 if s[i] = s[j], else max(L[i+1][j], L[i][j−1]) gives 7 (matching a brute force over all subsequences), for example B C A D A C B. The longest common substring and palindromic substring would be much shorter.

More Algorithms questions

Exams that ask this topic