#C14362. Longest Consecutive Sequence

    ID: 44003 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

You are given a list of integers. Your task is to determine the length of the longest subsequence (not necessarily contiguous in the input) in which the elements form a sequence of consecutive integers. The consecutive integers can appear in any order in the input list.

Note: Duplicates in the input list should be treated as a single element when forming a consecutive sequence.

Example: For the input list [100, 4, 200, 1, 3, 2], the longest consecutive sequence is [1, 2, 3, 4] and its length is 4.

inputFormat

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

  • The first line contains a single integer n which is the number of elements in the list.
  • The second line contains n space-separated integers.

outputFormat

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

## sample
6
100 4 200 1 3 2
4