Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Array A = [3, 1, 1, 1, 5, 2, 1]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly increasing). How many index sets give an increasing subsequence of the maximum possible length?

  1. A. 13
  2. B. 3
  3. C. 2
  4. D. 7

Correct answer: D. 7

The longest strictly increasing subsequence has length 2, and there are 7 index sets achieving it. Counting distinct value sequences merges equal choices, which is the trap here.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic