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]?
- A. 5
- B. 3
- C. 6
- 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.
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 [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…
- Using unit-cost insertions, deletions and substitutions, what is the minimum number of operations needed to turn the string 'bbabaac' into…