Data Structures & AlgorithmsHard

How many index triples i < j < k in 3 1 4 2 5 6 have A[i] < A[j] < A[k] (a strictly increasing subsequence of length 3)?

  1. A. 10
  2. B. 12
  3. C. 18
  4. D. 11

Correct answer: A. 10

A subsequence need not be contiguous, so enumerate index triples in order and test both strict inequalities. Allowing equal values, counting pairs instead, or checking only the outer two values each changes the answer.

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

Exams that ask this topic