#C10133. Longest Consecutive Sequence

    ID: 39305 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

Given an array of integers, determine the length of the longest consecutive elements sequence. A consecutive sequence is one where each number is exactly 1 greater than its predecessor. For instance, given the array 10 9 2 5 3 4 6 1 0 7 8, the longest sequence is (0, 1, 2, \ldots, 10) with a length of 11. Implement an efficient solution to solve this problem.

inputFormat

The input is read from standard input (stdin). The first line contains an integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers.

outputFormat

Output a single integer representing the length of the longest consecutive sequence. The answer should be printed to standard output (stdout).## sample

11
10 9 2 5 3 4 6 1 0 7 8
11