Data Structures & AlgorithmsModerateCodeforces Div2 C · TCS NQT

What is the length of the longest palindromic substring of "bananaracecarbnn"?

  1. A. 3
  2. B. 8
  3. C. 7
  4. D. 14

Correct answer: C. 7

Expand around each centre (for odd and even lengths) and keep the largest palindrome; Manacher's algorithm does this in O(n). Restricting to palindromic subsequences or counting distinct palindromes answers a different question.

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

Exams that ask this topic