#C6637. Longest Consecutive Sequence
Longest Consecutive Sequence
Longest Consecutive Sequence
Given a list of integers, your task is to find the length of the longest consecutive sequence of numbers. A consecutive sequence is defined as a set of numbers where each number in the sequence differs by 1 from its predecessor. The numbers in the list are in arbitrary order.
Formally, if the input list is \(A\), you need to find the maximum \(k\) such that there exists an integer \(x\) with
[ x,; x+1,; x+2,; \ldots,; x+(k-1) \in A ]
Note that the sequence does not need to appear in order in the input.
inputFormat
The input is given from stdin
and consists of two lines:
- The first line contains an integer \(n\) which denotes the number of integers.
- The second line contains \(n\) space-separated integers.
If \(n = 0\), the second line may be omitted.
outputFormat
Output a single integer to stdout
representing the length of the longest consecutive sequence.
7
100 4 200 1 3 2 5
5