Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional

Problem: The string "abcbaxyzzyxq" is given. What is the minimum number of characters that must be deleted so the remaining string is a palindrome (the remaining characters keep their order)?

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

Correct answer: D. 6

Deletions = length − longest palindromic subsequence = 12 − 6, where the LPS is xyzzyx (abcba has only 5). Keeping the first palindrome abcba gives 7, allowing the letters to be rearranged needs only 1 deletion, and taking the LCS of s with itself instead of its reverse gives 0.

More Coding Interview Problems questions

Exams that ask this topic