GATE Computer ScienceModerateGATE CS (PYQ pattern)

Characters may be added ONLY at the front of the string abacdcabxab. What is the minimum number of characters that must be added to make it a palindrome?

  1. A. 8
  2. B. 2
  3. C. 9
  4. D. 10

Correct answer: A. 8

Adding only at the front, we keep the longest palindromic prefix and mirror the rest in front. The longest palindromic prefix is aba (length 3), so 11 − 3 = 8 characters are needed. If insertions were allowed anywhere, 11 − LPS = 11 − 9 = 2 would suffice.

More Algorithms questions

Exams that ask this topic