Data Structures & AlgorithmsHardTCS NQT · Infosys

Problem: The string "racecar" is compressed by storing each character and the number of distinct palindromic substrings of length at least 2 that start at that character. What is the total number of distinct palindromic substrings of length at least 2 in "racecar"?

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

Correct answer: C. 3

Collect the distinct palindromic substrings of length at least two (such as 'aceca', 'cec', 'racecar') in a set. Counting by starting position gives a different total.

More Coding Interview Problems questions

Exams that ask this topic