Longest Increasing Subsequence

Given an integer array nums, return the length of the longest strictly increasing subsequence.

Follow up: Can you come up with an algorithm that runs in O(n log(n)) time complexity?

Example 1
Inputnums = [10,9,2,5,3,7,101,18]
Output4
The longest increasing subsequence is [2,3,7,101], therefore the length is 4.
Example 2
Inputnums = [0,1,0,3,2,3]
Output4
The longest increasing subsequence has length 4.

Constraints

  • 1 <= nums.length <= 2500
  • -10^4 <= nums[i] <= 10^4

Asked at 31 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate