Longest Increasing Subsequence

0

0 votes
Problem

For a given array with N elements, you need to find the length of the longest subsequence from the array such that all the elements of the subsequence are sorted in strictly increasing order.

A Strictly Increasing Sequence is when each term in the sequence is larger than the preceding term.

For example:

[1, 2, 3, 4] is a strictly increasing array, while [2, 1, 4, 3] is not.

 

Input Format:

The first line of input contains an integer 'N', representing the size of the array. The second line of input contains 'N' space-separated integers, representing the elements of the array.

Output Format:

The only output line contains one integer representing the length of the longest increasing subsequence.

Input Constraints,

1 <= N <= 105

-105 <= element <= 105

 

 

,

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

Length of longest subsequence is 3 i.e. [5, 11, 16] or [4, 11, 16].

Editor Image

?