Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT

How many DIFFERENT palindromic strings of length 3 occur as subsequences of "abcbaab" (each string counted once, however many index choices produce it)?

  1. A. 8
  2. B. 5
  3. C. 35
  4. D. 6

Correct answer: D. 6

A length-3 palindrome is determined by its outer letter x and middle letter y, so there are at most 26 × 26 candidates; test each for being a subsequence greedily. Counting index triples instead of distinct strings gives a larger number.

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

Exams that ask this topic