Longest Increasing Subsequence
Medium Dynamic Programming
nums is a list of whole numbers.
A subsequence of nums is some of its numbers, at least one, kept in the order they have in the list: numbers may be left out, but none moves. It is increasing when each of its numbers is larger than the one before it, so two equal numbers never follow each other in it.
Return the length of the longest increasing subsequence of nums.
Example 1
3, 4, 5, 6 leaves out 8 and 9 and keeps the rest in their order, each larger than the one before. Taking 8 or 9, as in 3, 8, 9, gives a shorter one, and none has 5 numbers.
Example 2
Example 3
Constraints
1 ≤ nums.length ≤ 10⁵-10⁹ ≤ nums[i] ≤ 10⁹
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
See the AI roundWatch the explanation
More Dynamic Programming
- Maximum SubarrayAI round · Medium
- Best Time to Buy and Sell StockAI round · Easy
- Climbing StairsAI round · Easy
- Coin ChangeAI round · Medium
- Unique PathsAI round · Medium