Data Structures & AlgorithmsHardAmazon · Microsoft OA

Using O(n²) DP (dp[i] = 1 + max(dp[j]) over all j < i with a[j] < a[i]), what is the length of the longest STRICTLY increasing subsequence of [7, 21, 7, 2, 20, 9, 4, 1, 19]?

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

Correct answer: A. 3

Each dp[i] holds the length of the longest strictly increasing subsequence ending at index i, built from smaller dp values at earlier strictly-smaller elements; the overall answer is the maximum dp value, 3. Allowing equal values to extend the subsequence (non-decreasing, not strictly increasing) can give a different count, 4.

More Coding Interview Problems questions

Exams that ask this topic