Dashboard
LC #300

Longest Increasing Subsequence

Pattern · ?AmazonGoogleMetaMicrosoft

Problem

Find the length of the longest strictly increasing subsequence.

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
4
Why
LIS: [2,3,7,101] or [2,5,7,101] — length 4

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗