Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2

Array A = [3, 1, 2, 3, 4, 1, 4, 1, 4]. 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. 21
  2. B. 3
  3. C. 1
  4. D. 4

Correct answer: B. 3

The longest strictly increasing subsequence has length 4, and there are 3 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