Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

What is the length of the longest palindromic subsequence of "bbbab"?

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

Correct answer: B. 4

Taking the b's around the a gives "bbbb" which is a palindrome of length 4. Substrings alone would give a shorter answer, but subsequences may skip characters.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic