#C13430. Longest Consecutive Sequence

    ID: 42968 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

Given an unsorted array of integers, find the length of the longest consecutive elements sequence.

Design an algorithm that runs in O(n) time.

For example, given the array [100, 4, 200, 1, 3, 2], the longest consecutive sequence is [1, 2, 3, 4] so its length is 4.

The input is given in two lines: the first line contains an integer n denoting the number of elements, and the second line contains n space-separated integers.

The output is a single integer representing the length of the longest consecutive sequence.

Note: If the array is empty, output 0.

inputFormat

The first line contains an integer n which represents the number of elements in the array.

The second line contains n space separated integers representing the array elements.

If n is 0, the second line may be omitted.

outputFormat

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

## sample
6
100 4 200 1 3 2
4

</p>