GATE Computer ScienceHardGATE CS (PYQ pattern)

What is the length of the longest palindromic substring (contiguous) of xabcbaxyzzyxabcdcbay?

  1. A. 12
  2. B. 6
  3. C. 8
  4. D. 10

Correct answer: A. 12

The substring cbaxyzzyxabc (positions 3 to 14) reads the same forwards and backwards. Expanding around the even centre between the two z characters keeps matching for 6 steps on each side: length 12. The odd palindromes abcba and abcdcba are shorter.

More Algorithms questions

Exams that ask this topic