#C8368. Longest Consecutive Sequence
Longest Consecutive Sequence
Longest Consecutive Sequence
You are given a list of integers and your task is to find the length of the longest consecutive sequence in the list. A consecutive sequence is a set of numbers that follow each other without interruption. For example, in the list [100, 4, 200, 1, 3, 2], the longest consecutive sequence is [1, 2, 3, 4] which has a length of 4.
The sequence is defined formally as follows: if \(a, a+1, a+2, \ldots, a+k\) are all present in the list, then the length of this sequence is \(k+1\). If the list is empty, the answer is 0.
Your program should read input from standard input and write the result to standard output.
inputFormat
The first line of input contains a single integer \(n\) which denotes the number of elements in the list. The second line contains \(n\) space-separated integers representing the list.
If \(n = 0\), the second line may be empty.
outputFormat
Output a single integer representing the length of the longest consecutive sequence.
## sample6
100 4 200 1 3 2
4
</p>