Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA

Problem: How many distinct palindromic substrings does "abacaba" contain (single characters count as palindromes, and distinct strings count once)?

  1. A. 12
  2. B. 4
  3. C. 7
  4. D. 3

Correct answer: C. 7

The distinct palindromes are a, b, c, aba, aca, bacab and abacaba: 7. Counting occurrences instead gives 12, leaving out single letters gives 4, and counting only the single letters gives 3.

More Coding Interview Problems questions

Exams that ask this topic