Data Structures & AlgorithmsModerateGATE CS · ICPC regional

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

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

Correct answer: B. 6

Patience sorting keeps the smallest tail for each length; there are 6 piles (e.g. 2, 4, 7, 8, 12, 14). The longest decreasing subsequence is 5, greedily extending from the first element gives only 13, 14 (2), and 14 is the array length.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic