Dashboard
#58. Longest Increasing SubsequenceMedium1-D Dynamic Programming

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

A subsequence is a sequence that can be derived from the given sequence by deleting some or no elements without changing the relative order of the remaining characters.

  • For example, "cat" is a subsequence of "crabt".

Example 1:

Input: nums = [9,1,4,2,3,3,7]

Output: 4

Explanation: The longest increasing subsequence is [1,2,3,7], which has a length of 4.

Example 2:

Input: nums = [0,3,1,3,2,3]

Output: 4

Constraints:

  • 1 <= nums.length <= 1000
  • -1000 <= nums[i] <= 1000
Examples
Example 1:
Input: nums = [9,1,4,2,3,3,7]
Output: 4
Example 2:
Input: nums = [0,3,1,3,2,3]
Output: 4
Constraints
  • `1 <= nums.length <= 1000`
  • `-1000 <= nums[i] <= 1000`
Prerequisites
Target: O(N) time • O(1) spaceArray / Binary Search / Dynamic Programming
Socratic AI Tutor
Gemini 3.8 Flash
Loading editor...

Click "Run" or press Ctrl+Enter to execute test cases.