Longest Ordered Subsequence
InterviewTime limit1sMemory limit128 MB
Given a sequence of N integers, find the length of the longest non-decreasing subsequence.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Array, Binary search, Greedy
- Solved
- No attempts yet
Problem
A numeric sequence is called ordered if . For a given sequence , a subsequence is any sequence with .
For example, the sequence has ordered subsequences such as and . All of its longest ordered subsequences have length 4, for example .
Given the sequence, find the length of its longest ordered subsequence.
Input
The first line contains the length of the sequence (). The second line contains integers — the elements of the sequence, each in the range from to , separated by spaces.
Output
Print a single integer: the length of the longest ordered subsequence of the given sequence.