#K5321. Longest Consecutive Sequence

    ID: 29481 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 consecutive elements sequence. For example, given the array ( [100, 4, 200, 1, 3, 2] ), the longest consecutive sequence is ( [1, 2, 3, 4] ) and its length is 4. Note that the sequence does not need to be contiguous in the array. You are required to read the input from standard input (stdin) and print the result to standard output (stdout).

inputFormat

The input consists of two lines. The first line contains a single integer ( n ) representing the number of elements in the array. The second line contains ( n ) space-separated integers denoting the elements of the array. If ( n ) is 0, then the array is empty.

outputFormat

Output a single integer denoting the length of the longest consecutive sequence found in the array.## sample

6
100 4 200 1 3 2
4