#C12636. Longest Consecutive Sequence
Longest Consecutive Sequence
Longest Consecutive Sequence
You are given a list of integers. Your task is to find and return the length of the longest consecutive sequence of integers in the list. A consecutive sequence is a sequence of numbers such that every number in the sequence differs by exactly \(1\) from its adjacent numbers. Note that the integers in the input list are not necessarily sorted and may contain duplicates.
For example, if the input list is \( [100, 4, 200, 1, 3, 2] \), the longest consecutive sequence is \( [1, 2, 3, 4] \) and its length is \(4\).
inputFormat
The first line contains an integer \( n \), indicating the number of elements in the list. The second line contains \( n \) space-separated integers.
outputFormat
Output a single integer denoting the length of the longest consecutive sequence in the list.
## sample6
100 4 200 1 3 2
4