#C12990. Longest Consecutive Sequence

    ID: 42478 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

You are given an unsorted array of integers. Your task is to find the length of the longest sequence of consecutive integers in the array. A consecutive sequence is defined as a set of integers where each number is one more than the previous one, i.e., for a sequence \(a, a+1, a+2, \ldots, a+k\), each adjacent pair satisfies \(a_{i+1} = a_i + 1\).

Example: For the array [100, 4, 200, 1, 3, 2], the longest consecutive sequence is [1, 2, 3, 4], and its length is 4.

Your program must be able to handle cases with negative numbers and duplicate values. It should read the input from standard input (stdin) and output the result to standard output (stdout).

inputFormat

The first line contains a single integer \(n\) denoting the number of elements in the array. The second line contains \(n\) space-separated integers representing the array elements. When \(n = 0\), there is no second line.

outputFormat

Output a single integer representing the length of the longest consecutive elements sequence in the array.

## sample
6
100 4 200 1 3 2
4