#C1556. Longest Consecutive Sequence
Longest Consecutive Sequence
Longest Consecutive Sequence
Given an array of integers, your task is to find the length of the longest consecutive sequence of numbers in the array. A consecutive sequence is a set of numbers that can be arranged in increasing order where each element differs by 1 from its predecessor. Note that the consecutive sequence does not have to appear in sorted order in the input and duplicate numbers are ignored.
Formally, if we denote the array by \(arr\), you are to compute the value:
\(\max \{ \ell : \exists x, x+1,\dots,x+\ell-1 \text{ all in } arr \}\)
Your solution must read from standard input and output the result to standard output.
inputFormat
The first line of input contains an integer \(n\) which represents the number of elements in the array. The second line contains \(n\) space-separated integers representing the elements of the array.
outputFormat
Output a single integer representing the length of the longest consecutive sequence present in the array.
## sample6
100 4 200 1 3 2
4