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]?
- A. 5
- B. 6
- C. 2
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- 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…
- What is the length of the longest strictly increasing subsequence (not necessarily contiguous) of [2, 1, 6, 5, 10, 4, 7, 9, 3, 11, 8]?
- What is the length of the longest strictly increasing subsequence (not necessarily contiguous) of [3, 12, 1, 13, 4, 2, 14, 11, 10, 6, 8…
- What is the length of the longest strictly increasing subsequence (not necessarily contiguous) of [11, 4, 12, 7, 3, 2, 13, 8, 6, 14, 1, 5…
- Using unit-cost insertions, deletions and substitutions, what is the minimum number of operations needed to turn the string 'bcacba' into…
- Using unit-cost insertions, deletions and substitutions, what is the minimum number of operations needed to turn the string 'bcccb' into…