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]?
- A. 4
- B. 13
- C. 11
- 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.
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
- Elements 0 to 6 start as singletons. For each call union(a, b), in order: let ra and rb be the roots of a and b. If ra = rb nothing…
- Elements 0 to 5 start as singletons. For each call union(a, b), in order: let ra and rb be the roots of a and b. If ra = rb nothing…
- Elements 0 to 7 start as singletons. For each call union(a, b), in order: let ra and rb be the roots of a and b. If ra = rb nothing…
- A Fenwick tree t[1..6] (1-indexed, all zero at the start) is updated by add(i, v): set j = i, then while j ≤ n do { t[j] += v; j += j & −j…
- A Fenwick tree t[1..6] (1-indexed, all zero at the start) is updated by add(i, v): set j = i, then while j ≤ n do { t[j] += v; j += j & −j…
- A bottom-up segment tree for the sum over n = 8 cells stores leaf i at t[n + i] and builds t[i] = t[2i] op t[2i + 1] for i = n − 1 down to…