Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE

Problem: In the string "racecarbanana", find the number of distinct palindromic substrings of length at least 3.

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

Correct answer: B. 6

The distinct palindromes of length ≥ 3 are racecar, aceca, cec, ana, anana and nan: 6. Counting occurrences counts 'ana' twice (7), dropping the length filter adds the single letters r, a, c, e, b, n (12), and keeping only maximal palindromes gives 2.

More Coding Interview Problems questions

Exams that ask this topic