Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT

What is the length of the longest substring of "abcbxaxba" that becomes a palindrome after deleting AT MOST ONE character from it?

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

Correct answer: C. 6

Check each substring with two pointers, allowing one skip on a mismatch: 'abcbxa' (drop x), 'cbxaxb' and 'bxaxba' all work, so the answer is 6. The longest true palindrome, 'bxaxb', is 5; the whole string (9) needs more than one deletion, and 3 is 'bcb'.

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

Exams that ask this topic