#K79967. Longest Consecutive Sequence

    ID: 35426 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

Given an unsorted list of integers, your task is to determine the length of the longest consecutive elements sequence. Your solution must run in \(O(n)\) time complexity.

For example, given the array [100, 4, 200, 1, 3, 2], the longest consecutive sequence is [1, 2, 3, 4], so the expected result is 4.

inputFormat

The input is given from stdin and consists of two lines:

  • The first line contains an integer \(n\), which is the number of elements in the list.
  • The second line contains \(n\) space-separated integers.

outputFormat

Output a single integer to stdout, representing the length of the longest consecutive sequence in the given list.

## sample
6
100 4 200 1 3 2
4

</p>