Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

How many distinct subsequences (including the empty string) does "aab" have?

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

Correct answer: C. 6

Distinct strings: '', a, b, aa, ab, aab = 6; the two ways to pick one a collapse into one string. Forgetting the empty string gives 5, 3 is the length and 2 the number of distinct letters.

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

Exams that ask this topic