#C11094. Longest Consecutive Sequence

    ID: 40372 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

Given a list of integers, your task is to determine the length of the longest sequence of consecutive integers present in the list. A consecutive sequence is defined as a sequence where each element is exactly one more than the previous element, i.e., a sequence of the form \(x, x+1, x+2, \ldots, x+(L-1)\).

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

You are required to read the input from stdin and output the result to stdout.

inputFormat

The first line of input contains an integer \(L\), the number of elements in the list. The following \(L\) lines each contain one integer from the list.

Example:

6
100
4
200
1
3
2

outputFormat

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

Example:

4
## sample
6
100
4
200
1
3
2
4