#C12102. Longest Consecutive Subsequence
Longest Consecutive Subsequence
Longest Consecutive Subsequence
Given a list of integers, your task is to find the length of the longest consecutive subsequence present in the list. A consecutive subsequence is a set of integers such that each number in the set is exactly one more than its previous number. The integers in the list may be in any order, and duplicates may exist.
Example: For the list [1, 9, 3, 10, 4, 20, 2], the longest consecutive subsequence is [1, 2, 3, 4] which has a length of 4.
Note: The consecutive subsequence does not need to be contiguous in the original list.
inputFormat
The input consists of two lines. The first line contains a single integer n representing the number of elements in the list. The second line contains n space-separated integers representing the elements of the list.
If n is 0, the list is empty.
outputFormat
Output a single integer representing the length of the longest consecutive subsequence.
## sample0
0