#P1420. Longest Consecutive Subsequence
Longest Consecutive Subsequence
Longest Consecutive Subsequence
You are given a sequence of n positive integers. Your task is to find the length of the longest subsequence of consecutive numbers in the given order. Here, consecutive numbers are defined as a sequence of natural numbers in increasing order where each number is exactly one greater than the previous one. Formally, if a subsequence consists of elements a[i], a[i+1], ..., a[j], then it is consecutive if \(a[i+1] = a[i] + 1,\ a[i+2] = a[i+1] + 1,\dots, a[j] = a[j-1] + 1\).
inputFormat
The first line contains an integer n representing the length of the sequence. The second line contains n positive integers separated by spaces.
outputFormat
Output a single integer: the length of the longest consecutive subsequence.
sample
6
1 2 5 3 4 6
2