Longest Increasing Subsequence 2
InterviewTime limit1sMemory limit512 MB
Given up to 1,000,000 numbers, compute the length of the longest strictly increasing subsequence.
- Level
Medium4 of 10
- Topics
- Binary search, Dynamic programming
- Solved
- No attempts yet
Problem
Given a sequence , write a program that computes 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. A subsequence is increasing when every element is strictly smaller than the element right after it. Two elements with the same value cannot sit next to each other in one increasing subsequence.
For example, if , the longest increasing subsequence is and its length is .
Input
The first line contains the size of the sequence . ()
The second line contains , separated by single spaces. ()
Output
Print the length of the longest increasing subsequence of on the first line.