Data Structures & AlgorithmsHardGATE CS · ICPC regional

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

  1. A. 4
  2. B. 13
  3. C. 11
  4. D. 6

Correct answer: D. 6

Patience sorting keeps the smallest tail for each length; there are 6 piles (e.g. 1, 4, 5, 8, 12, 13). Greedily extending from the first element gives 1, 11, 12, 13 = 4, 13 is the array length, and adding the LIS and LDS (6 + 5) gives 11.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic