Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 D

What is the minimum number of characters that must be inserted at the FRONT of "abaccabb" to make the whole string a palindrome?

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

Correct answer: C. 6

Find the longest suffix of s that is a palindrome (equivalently the longest palindromic prefix of reverse(s), computed with a prefix function). Adding one character per unmatched letter at the front is the answer. Using the longest palindromic subsequence instead counts a different quantity.

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

Exams that ask this topic