Dynamic Programming
LC #300Medium
Longest Increasing Subsequence
Dynamic Programming
AmazonGoogleMetaMicrosoftProblem
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
Input
nums = [10, 9, 2, 5, 3, 7, 101, 18]Output
4Why
LIS: [2,3,7,101] or [2,5,7,101] — length 4