Longest Increasing Subsequence
You are given a sequence of integers. A subsequence is formed by deleting zero or more elements without changing the order of the remaining elements.
Find the length of the longest subsequence whose values are strictly increasing.
Input
The first line contains an integer n, the length of the sequence.
The second line contains n integers: a1,a2,…,an.
Output
Print one integer: the length of the longest strictly increasing subsequence.
Constraints
- 1≤n≤5000
- −109≤ai≤109
Example 1
8
10 9 2 5 3 7 101 18
4
Explanation
One longest increasing subsequence is 2,3,7,101.
Example 2
5
5 4 3 2 1
1
Example 3
6
2 2 2 2 2 2
1
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.