Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

What is the length of the longest palindromic substring of xabacdcabay?

  1. A. 8
  2. B. 11
  3. C. 13
  4. D. 9

Correct answer: D. 9

The longest palindrome is abacdcaba, centred on the d. Expanding around each of the 2n-1 centres finds the maximum in O(n^2) time, and Manacher's algorithm does it in O(n).

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

Exams that ask this topic