#K2531. Longest Consecutive Sequence

    ID: 24757 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

Given an integer array, your task is to find the length of the longest sequence of consecutive integers that can be formed from the array elements. The consecutive numbers can appear in any order in the array.

Note: The sequence must consist of consecutive integers, and duplicate values should be treated as one.

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

inputFormat

The input is read from stdin and consists of two lines. The first line is an integer n representing the number of elements in the array. The second line contains n space-separated integers.

If n is 0, it indicates an empty array.

outputFormat

Output the length of the longest sequence of consecutive integers found in the array. The output should be written to stdout as a single integer.

## sample
6
100 4 200 1 3 2
4