#C8926. Longest Consecutive Subsequence

    ID: 52962 Type: Default 1000ms 256MiB

Longest Consecutive Subsequence

Longest Consecutive Subsequence

You are given an array of integers. Your task is to determine the length of the longest subsequence of consecutive integers. A consecutive sequence is defined as a sequence of numbers that can be represented in the form \(n, n+1, n+2, \dots, n+k\), where \(k \geq 0\).

For example, given the array [100, 4, 200, 1, 3, 2, 101], the longest consecutive subsequence is \(1, 2, 3, 4\) and its length is 4.

Your solution should read the input from stdin and output the result to stdout.

inputFormat

The input is provided via standard input and has the following format:

  • The first line contains a single integer \(n\) denoting the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

Output a single integer to standard output which is the length of the longest subsequence of consecutive integers found in the array.

## sample
7
100 4 200 1 3 2 101
4