#C10531. Longest Consecutive Sequence

    ID: 39747 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

Given an unsorted array of integers, the task is to find the length of the longest consecutive sequence.

A consecutive sequence is defined as a sequence of numbers where each number is exactly 1 greater than the previous one. Duplicate numbers should be considered only once.

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

inputFormat

The first line of input contains an integer n denoting the number of elements in the array. The second line contains n space-separated integers.

outputFormat

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

## sample
6
100 4 200 1 3 2
4