#K88537. Longest Consecutive Sequence

    ID: 37330 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

Given an array of integers, find the length of the longest sequence of consecutive numbers. Two numbers are consecutive if they differ by exactly one. For instance, in the array \( [100, 4, 200, 1, 3, 2] \), the longest consecutive sequence is \( [1, 2, 3, 4] \) with a length of 4.

The input is provided via standard input (stdin) and the output should be printed to standard output (stdout). The first line of input contains an integer \( n \) which denotes the number of elements in the array. The second line contains \( n \) space-separated integers. If \( n = 0 \), the array is empty and the answer is 0.

inputFormat

The first line contains an integer \( n \) (\( n \geq 0 \)). If \( n > 0 \), 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 elements sequence found in the array.

## sample
6
100 4 200 1 3 2
4

</p>