algorythms
Dynamic Programming
LC #300Medium

Longest Increasing Subsequence

Dynamic Programming
AmazonGoogleMetaMicrosoft

Problem

Find the length of the longest strictly increasing subsequence.

dynamic-programmingbinary-search

Constraints

  • 1 ≤ n ≤ 2500
  • -10⁴ ≤ nums[i] ≤ 10⁴
  • O(n log n) solution exists but O(n²) is accepted

Example

Inputnums = [10, 9, 2, 5, 3, 7, 101, 18]
Output4
Why

LIS: [2,3,7,101] or [2,5,7,101] — length 4

Hints — reveal one at a time