Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many palindromic substrings (counting each occurrence by position, length 1 and up included) does "abacaba" contain?

  1. A. 10
  2. B. 12
  3. C. 13
  4. D. 3

Correct answer: B. 12

Expand around each of the 2n - 1 centres and count expansions. Odd centres dominate here, and each centre contributes its maximal radius plus smaller ones.

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

Exams that ask this topic