#K63597. Longest Consecutive Sequence Range
Longest Consecutive Sequence Range
Longest Consecutive Sequence Range
Given an unordered list of integers, your task is to compute the length of the longest sequence of consecutive numbers that can be formed from the list. For example, given the list [10, 5, 9, 2, 3, 8, 6, 4, 7, 1], the longest consecutive range is 10 because the numbers from 1 to 10 form a consecutive sequence.
The consecutive sequence does not need to be in order in the input. You are expected to design an efficient solution that can handle large inputs. In terms of mathematics, if you are given a set \( S \) of integers, consider all subsets \( T \subseteq S \) such that if \( x \) and \( x+1 \) belong to \( T \), then \( T \) forms a consecutive sequence. Return the length of the longest such subset.
Input Example:
10
10 5 9 2 3 8 6 4 7 1
Output Example:
10
inputFormat
The first line contains a single integer \( n \) representing the number of elements in the list. The second line contains \( n \) space-separated integers.
outputFormat
Output a single integer which is the length of the longest consecutive sequence that can be formed from the given integers.
## sample10
10 5 9 2 3 8 6 4 7 1
10
</p>