#C296. Longest Consecutive Subsequence
Longest Consecutive Subsequence
Longest Consecutive Subsequence
Given an unsorted array of integers, find the length of the longest sequence of consecutive numbers. A consecutive sequence is defined as a set of numbers where each number differs by one from its predecessor. Formally, for some integer \( n \), a consecutive sequence is \( \{n, n+1, \ldots, n+k\} \) and the answer is \( k+1 \), the length of this sequence. Duplicates may be present in the array, but they are treated as a single occurrence.
Your task is to compute the length of the longest such sequence. If the list is empty, the answer is 0.
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains a single integer \( N \), the number of elements in the array.
- The second line contains \( N \) space-separated integers representing the elements of the array.
If \( N = 0 \), no further input is provided.
outputFormat
Output a single integer via standard output (stdout), representing the length of the longest consecutive subsequence in the array.
## sample5
1 2 3 4 5
5
</p>