#C4960. Longest Consecutive Sequence

    ID: 48556 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

Given a list of integers, your task is to find the length of the longest sequence of consecutive integers. Note that the numbers may be provided in any order and the consecutive sequence does not require the numbers to appear contiguously in the list.

A consecutive sequence is defined as a set of integers \( \{a, a+1, a+2, \dots, a+k\} \) for some integer \( a \) and non-negative integer \( k \).

For example, given the list [100, 4, 200, 1, 3, 2], the longest consecutive sequence is [1, 2, 3, 4] which has a length of 4.

inputFormat

The input consists of two lines:

  • The first line contains an integer \( n \) representing the number of elements.
  • The second line contains \( n \) space-separated integers.

outputFormat

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

## sample
6
100 4 200 1 3 2
4

</p>