Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

What is the minimum number of characters you must delete from "abcbdaxyzyx" so that the remaining string is a palindrome?

  1. A. 10
  2. B. 6
  3. C. 5
  4. D. 9

Correct answer: B. 6

The kept characters form a palindromic subsequence, so the answer is n − LPS = 11 − 5 = 6 (for example keep xyzyx or abcba). Printing the LPS length itself gives 5; 9 keeps only a matching pair and 10 a single character.

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

Exams that ask this topic