Data Structures & AlgorithmsHardProduct Company SDE · DP with binary search

Problem: In the O(n log n) longest increasing subsequence algorithm, the array tails[k] is maintained over the input. What does tails[k] represent?

  1. A. The largest last value of an increasing subsequence of length k + 1
  2. B. The smallest possible last value of an increasing subsequence of length k + 1
  3. C. The sum of the lengths of all increasing subsequences
  4. D. The index of the k-th element of the input

Correct answer: B. The smallest possible last value of an increasing subsequence of length k + 1

Keeping tails sorted lets each new value replace the first tail that is at least as large via binary search, so the list stays sorted and its length is the LIS length.

More Coding Interview Problems questions

Exams that ask this topic