Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA

Problem: What is the length of the longest strictly increasing subsequence of the sequence 10, 9, 2, 5, 3, 7, 101, 18, 4, 6, 8, 1, 12?

  1. A. 6
  2. B. 12
  3. C. 3
  4. D. 5

Correct answer: A. 6

Patience sorting ends with tails [1, 3, 4, 6, 8, 12], so the LIS length is 6 (e.g. 2, 3, 4, 6, 8, 12). Reporting the last tail value gives 12, the longest contiguous increasing run is only 3 (2, 5 or 3, 7, 101), and the longest decreasing subsequence is 5.

More Coding Interview Problems questions

Exams that ask this topic