Data Structures & AlgorithmsVery hardProduct placement · Amazon/Microsoft

What is the minimum number of characters that must be APPENDED to the end of "abacdcab" to make it a palindrome? (Find the longest palindromic suffix, e.g. with KMP on reverse(s) + '#' + s.)

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

Correct answer: C. 1

The longest suffix that is already a palindrome is "bacdcab"; the 1 characters before it must be mirrored onto the end. Prepending would instead need 5 characters.

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

Exams that ask this topic