#C14478. Longest Consecutive Sequence

    ID: 44131 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

Given an unsorted array of integers, your task is to find the length of the longest consecutive elements sequence. The sequence elements do not need to be adjacent in the array but must be consecutive in value.

Note: Your algorithm should ideally run in O(n) time.

For example, for the input array [100, 4, 200, 1, 3, 2], the longest consecutive sequence is [1, 2, 3, 4] with a length of 4.

inputFormat

The input is given via standard input. The first line contains a single integer n which represents the number of elements in the array. The second line contains n space-separated integers. If n is 0, the second line may be empty.

outputFormat

Output a single integer to standard output representing the length of the longest consecutive elements sequence.

## sample
6
100 4 200 1 3 2
4

</p>