#C7349. Longest Consecutive Timestamps Sequence

    ID: 51210 Type: Default 1000ms 256MiB

Longest Consecutive Timestamps Sequence

Longest Consecutive Timestamps Sequence

You are given an integer n and a list of n integer timestamps. Your task is to determine the length of the longest sequence of consecutive timestamps. Two timestamps are consecutive if their difference is exactly 1.

Input Format: The first line contains an integer n representing the number of timestamps. The second line contains n space-separated integers.

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

Mathematical Formulation:

Let \(S\) be the set of timestamps. For any \(x \in S\) that does not have \(x-1\) in \(S\), define the sequence length starting from \(x\) as:

[ L(x) = 1 + \max{ k : x+1, x+2, \dots, x+k \in S } ]

The final answer is \(\max_{x \in S \text{ and } (x-1 \not\in S)} L(x)\).

inputFormat

The first line of input is an integer n (\(1 \leq n \leq 10^5\)), the number of timestamps. The second line contains n space-separated integers representing the timestamps.

outputFormat

Output a single integer denoting the length of the longest consecutive timestamps sequence.

## sample
6
10 20 30 31 32 33
4