Data Structures & AlgorithmsVery hardCodeforces Div 2 C · ICPC regional
What is the length of the longest strictly increasing subsequence of [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]? Use the patience-sorting method with binary search.
- A. 5
- B. 4
- C. 3
- D. 7
Correct answer: B. 4
Maintain tails[k], the smallest possible tail of an increasing subsequence of length k+1, and replace the first tail that is not smaller than x. The length of tails is the answer; the strict version uses bisect_left, which is what makes equal values not extend the sequence.
More Coding Interview Problems questions
- Sorted array [1, 2, 7, 8, 11, 15]. How many index triples i < j < k satisfy a[i] + a[j] + a[k] = 18?
- Four jobs have processing times [6, 3, 5, 2]. They run one at a time in some order, and job at position i (1-based) incurs cost i times…
- For the values [2, 5, 3, 8, 1, 6], how many values give remainder 1 or 2 when divided by 3 (counted once for each value)?
- Array [4, 4, 7, 1, 7, 2]. How many index pairs i < j have equal values a[i] = a[j]?
- Array [3, 7, 2, 9, 4]. How many contiguous subarrays sum to exactly 9?
- Problem: Fresh oranges (1) rot their neighbours (4-directional) one minute at a time; 0 is empty and 2 is rotten. How many minutes until…