Data Structures & AlgorithmsHardProduct Company SDE · Infosys OA

Problem: How many palindromic substrings does "aabbaa" contain? Two substrings count as different if they occupy different index ranges, even when their letters match.

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

Correct answer: A. 11

Single letters give 6, the length-2 matches aa, bb, aa give 3, abba gives 1 and aabbaa gives 1, for 11 occurrences. Counting distinct palindromic strings merges the repeats (6), skipping single letters gives 5, and 21 counts every substring.

More Coding Interview Problems questions

Exams that ask this topic