Data Structures & AlgorithmsHardGATE CS · ICPC regional

How many distinct non-empty palindromic subsequences does the string abcba have (distinct as strings, not as index sets)?

  1. A. 10
  2. B. 12
  3. C. 7
  4. D. {C+5}

Correct answer: A. 10

Count distinct strings, not index sets: the palindromes are collected into a set first, so a palindrome that arises from several index choices is counted once. Including the empty string would add one more.

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

Exams that ask this topic