Longest Rising Subsequence
A subsequence of a list keeps some of its numbers, in their original order, and drops the rest; the numbers kept do not have to be next to each other. A subsequence is rising when each number in it is strictly larger than the one before.
Given a list of integers nums, return the length of its longest rising subsequence.
Examples
nums = [10, 9, 2, 5, 3, 7, 101, 18] → 4
nums = [0, 1, 0, 3, 2, 3] → 4
nums = [7, 7, 7, 7] → 1
nums = [5, 4, 3, 2, 1] → 1In the first example 2, 3, 7, 18 (or 2, 5, 7, 101) rises all the way. In the third, equal numbers do not rise.
Constraints
- Between 0 and 20,000 numbers, each between -1,000,000,000 and 1,000,000,000.
- Aim for O(n log n): the table that compares every number with every earlier one is O(n²).
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 9 on the judge, 5 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.