Data Structures & AlgorithmsHard

How many index triples i < j < k in "aabbccabc" spell the subsequence 'abc' (characters need not be adjacent)?

  1. A. 1
  2. B. 15
  3. C. 21
  4. D. 12

Correct answer: B. 15

A DP over the pattern prefixes adds, for each character, the number of ways to complete each prefix before it; processing the pattern in reverse prevents reusing one character twice. Contiguous matches, products of letter counts, or a different subtraction each give other totals.

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

Exams that ask this topic