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.

  1. A. 5
  2. B. 4
  3. C. 3
  4. 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

Exams that ask this topic