Longest Increasing Subsequence
InterviewTime limit1sMemory limit256 MB
Find the length of the longest strictly increasing subsequence of the given sequence.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Binary search
- Solved
- No attempts yet
Problem
Given a sequence , write a program that finds the length of its longest increasing subsequence.
A subsequence of is what remains after deleting zero or more elements and keeping the rest in their original order. An increasing subsequence is one whose values grow strictly from left to right, so two elements with the same value cannot both be chosen.
For example, when , the longest increasing subsequence is 10, 20, 30, 50, and its length is 4.
Input
The first line contains the size of the sequence ().
The second line contains , separated by spaces ().
Output
Print the length of the longest increasing subsequence of on the first line.