Data Structures & AlgorithmsHardAmazon · Microsoft coding round

The array is [3, 3, 4, 4, 5, 1, 2, 2, 6, 3, 7]. What is the length of its longest non-decreasing (not strictly increasing) subsequence?

  1. A. 5
  2. B. 6
  3. C. 8
  4. D. 7

Correct answer: D. 7

One longest choice is 3, 3, 4, 4, 5, 6, 7 with length 7, while a strict LIS only reaches 5. Duplicates may be reused, so the binary-search method must use upper bound instead of lower bound.

More Coding Interview Problems questions

Exams that ask this topic