#C6538. Longest Consecutive Subsequence

    ID: 50309 Type: Default 1000ms 256MiB

Longest Consecutive Subsequence

Longest Consecutive Subsequence

In this problem, you are given an unsorted array of integers. Your task is to determine the length of the longest consecutive subsequence. A consecutive subsequence is defined such that for any two adjacent numbers (a) and (b) in the sequence, (b = a + 1).

For example, given the array [100, 4, 200, 1, 3, 2], the longest consecutive subsequence is [1, 2, 3, 4], so the answer is 4.

It is guaranteed that the solution can be implemented to run in (O(n)) time complexity by using an appropriate data structure.

inputFormat

The first line of input contains a single integer (n) denoting the number of elements in the array. The second line contains (n) space-separated integers representing the elements of the array.

outputFormat

Output a single integer denoting the length of the longest consecutive subsequence.## sample

6
100 4 200 1 3 2
4

</p>