Data Structures & AlgorithmsHardGATE CS · ICPC regional

How many subsequences of length 3 of the string abcabc are palindromes (distinct index choices count separately)?

  1. A. 20
  2. B. 6
  3. C. 3
  4. D. 12

Correct answer: B. 6

Fix equal outer letters (a at 0 and 3, b at 1 and 4, c at 2 and 5); the middle must lie strictly between them, giving 2 choices each: 6. Ignoring that the middle must be between them gives 12, 3 counts only the outer pairs and 20 counts all triples.

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

Exams that ask this topic