Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many subsequences (chosen by index) of "aabbabcaccb" spell exactly the word abc?

  1. A. 11
  2. B. 1
  3. C. 21
  4. D. 25

Correct answer: C. 21

Use dp[j] = number of ways to match the first j letters of the pattern so far; scanning the text, each letter adds dp[j−1] to dp[j], iterating j downwards. Counting only contiguous occurrences misses the gapped ones.

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

Exams that ask this topic