Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The string "aaaa" has how many distinct palindromic substrings (counting each distinct string once, of any length ≥ 1)?

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

Correct answer: B. 4

All substrings of a run of equal letters are palindromes, so the distinct ones are a, aa, aaa and aaaa. Counting index ranges instead gives 10.

More Coding Interview Problems questions

Exams that ask this topic