Data Structures & AlgorithmsModerateProduct Company SDE · Amazon/Microsoft-style OA

Problem: Find the length of the longest palindromic substring of the string "abacdfgdcabazyx".

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

Correct answer: C. 3

Expanding around every centre (both odd and even) finds the longest palindrome in O(n²). Only centre-expansion for odd lengths would miss even ones like 'aa' inside a longer string.

More Coding Interview Problems questions

Exams that ask this topic