Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT

How many DISTINCT palindromic strings (of any length ≥ 1) occur as subsequences of "abab"?

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

Correct answer: B. 6

Enumerate the non-empty subsequences by index and keep the palindromes as a set of strings. The ones that occur are a, b, aa, bb, aba and bab. Counting index subsets instead of distinct strings gives a larger number.

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

Exams that ask this topic