Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: Count the odd-length palindromic substrings of "racecarxyz" that are centred at index 3 (the 'e' of "racecar"), where the centre itself counts as a palindrome of length 1.

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

Correct answer: B. 4

Expand outward from the centre while the mirrored characters match; each successful radius is one palindrome. Counting all palindromes in the string instead answers a different question.

More Coding Interview Problems questions

Exams that ask this topic