Data Structures & AlgorithmsHardGATE CS · ICPC regional

What is the length of the longest strictly increasing subsequence (not necessarily contiguous) of [9, 3, 1, 8, 13, 6, 2, 5, 10, 14, 11, 7, 12, 4]?

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

Correct answer: C. 6

Patience sorting keeps the smallest tail for each length; there are 6 piles (e.g. 1, 2, 5, 10, 11, 12). The longest decreasing subsequence is 5, greedily extending from the first element gives 9, 13, 14 = 3, and 14 is the array length.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic