#C9121. Longest Consecutive Subsequence
Longest Consecutive Subsequence
Longest Consecutive Subsequence
Given an integer array, your task is to find the length of the longest consecutive subsequence in the array. A consecutive subsequence is a sequence of numbers where each number is exactly one greater than the previous number. For instance, in the array [100, 4, 200, 1, 3, 2, 5]
, the longest consecutive subsequence is [1, 2, 3, 4, 5]
which has a length of 5.
You can use the following mathematical formulation: if a subsequence is given by \(a_1, a_2, \dots, a_k\), then it must satisfy \(a_i = a_1 + (i - 1)\) for \(i = 1, 2, \dots, k\).
Your solution must read input from standard input and print the answer to standard output.
inputFormat
The first line contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers which constitute the array.
outputFormat
Output a single integer representing the length of the longest consecutive subsequence in the array.
## sample7
100 4 200 1 3 2 5
5