Data Structures & AlgorithmsHardCodeforces Div2 B · DP warm-up

Problem: What is the time complexity of computing the longest increasing subsequence using patience-sorting with binary search, versus the naive O(n^2) DP?

  1. A. O(n log n) with binary search over the 'tails' array, versus O(n^2) for the naive DP
  2. B. Both are O(n^2)
  3. C. O(n) with binary search, O(n log n) for the DP
  4. D. O(log n) with binary search, O(n) for the DP

Correct answer: A. O(n log n) with binary search over the 'tails' array, versus O(n^2) for the naive DP

Maintaining the smallest possible tail value for each achievable subsequence length and binary-searching where a new element fits brings the naive O(n^2) DP down to O(n log n).

More Coding Interview Problems questions

Exams that ask this topic