Data Structures & AlgorithmsVery hardICPC regional · GATE CS

How many non-empty subsequences of "abcbab" (chosen by index, so the same letters at different positions count as different subsequences) are palindromes?

  1. A. 18
  2. B. 20
  3. C. 63
  4. D. 3

Correct answer: B. 20

Enumerate or count with an interval DP where cnt[i][j] adds cnt[i+1][j] + cnt[i][j−1] − cnt[i+1][j−1], plus the outer pair when s[i] = s[j]. Counting distinct palindromic strings instead of index choices merges repeated patterns.

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

Exams that ask this topic