Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many substrings of length exactly 4 of the string abbaccddcc are palindromes?

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

Correct answer: B. 2

Check each window of length 4 against its reverse. Only the substrings whose first and last characters match, and whose middle pair is also a mirror, qualify.

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

Exams that ask this topic