Longest Increasing Subsequence
MediumPython 3Dynamic programmingSubsequencesArrays
You are given an integer array nums. Return the length of the longest strictly increasing subsequence.
A subsequence is a sequence derived from the array by deleting zero or more elements without changing the order of the remaining elements. "Strictly increasing" means each element is greater than the one before it (equal values cannot both be used).
Constraints: - 0 <= len(nums) <= 2500 - -10^4 <= nums[i] <= 10^4
Examples: [10, 9, 2, 5, 3, 7, 101, 18] -> 4 (e.g. 2, 3, 7, 101 or 2, 5, 7, 101) [3, 2, 6, 4, 5, 1] -> 3 (2, 4, 5) [0, 1, 0, 3, 2, 3] -> 4 (0, 1, 2, 3) [7, 7, 7, 7, 7] -> 1 (equal values can't extend each other) [] -> 0
Python 3, run in your browser. Run tests runs the problem's own tests with a free account; the AI interviewer reads your code and your runs in a practice interview.
Loading the editor…