Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many substrings of length 2 of "abcba" read the same forwards and backwards?

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

Correct answer: D. 0

A length-2 palindrome needs equal adjacent characters. The string has none, so the count is zero; the other options check gap-2 equality, which is the length-3 condition.

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

Exams that ask this topic