Data Structures & AlgorithmsModerateTCS Digital · Infosys pattern

How many DISTINCT palindromic substrings (counted as strings, not by position) does 'abaab' have?

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

Correct answer: C. 5

The palindromes are a, b, aba, aa and baab. Counting occurrences by position instead (a×3, b×2, aba, aa, baab) gives 8; forgetting the even-length ones (aa, baab) gives 3. Distinct strings: 5.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic