#K36682. Longest Consecutive Subsequence
Longest Consecutive Subsequence
Longest Consecutive Subsequence
Your task is to determine the length of the longest subsequence of consecutive integers in a given array. A subsequence is considered consecutive if each adjacent pair of integers differs by exactly , i.e. for a consecutive subsequence (a, a+1, a+2, \dots, a+k).
For example, if the array is [100, 4, 200, 1, 3, 2], the longest consecutive subsequence is [1, 2, 3, 4] with length 4. Make sure to consider duplicate numbers appropriately by treating them as one occurrence.
inputFormat
The input is given via standard input (stdin) and consists of two lines. The first line contains an integer (N), representing the number of elements in the array. The second line contains (N) space-separated integers.
outputFormat
Output a single integer to standard output (stdout), which is the length of the longest subsequence of consecutive integers.## sample
6
100 4 200 1 3 2
4
</p>