#K64592. Longest Consecutive Subsequence

    ID: 32009 Type: Default 1000ms 256MiB

Longest Consecutive Subsequence

Longest Consecutive Subsequence

Given an unsorted list of integers, your task is to determine the length of the longest sequence of consecutive integers present in the list.

Definition: A consecutive sequence is a set of numbers where each number differs by exactly 1 from its predecessor. For example, in the list [100, 4, 200, 1, 3, 2], the longest consecutive sequence is [1, 2, 3, 4] with a length of 4.

Your solution should read input from standard input (stdin) and print the result to standard output (stdout).

inputFormat

The input consists of two lines. The first line contains a single integer n, representing the number of elements in the list. The second line contains n space-separated integers.

outputFormat

Output a single integer representing the length of the longest consecutive subsequence in the list.## sample

6
100 4 200 1 3 2
4