#C6966. Longest Consecutive Subarray

    ID: 50784 Type: Default 1000ms 256MiB

Longest Consecutive Subarray

Longest Consecutive Subarray

Given an array of integers, your task is to find the length of the longest subsequence of consecutive integers present in the array. The elements of the consecutive subsequence do not need to appear in sorted order in the input array. For example, if the input array is [1, 94, 93, 1000, 92, 91, 90], the longest consecutive subsequence is [90, 91, 92, 93, 94] with a length of 5.

The relation between consecutive numbers is defined by the equation: \( x_{i+1} = x_i + 1 \).

Your program should read from standard input and write the result to standard output.

inputFormat

The input begins with an integer \( n \) (\(1 \leq n \leq 10^5\)) representing the number of elements in the array. The next line contains \( n \) space-separated integers, which can be positive, negative, or zero.

Example:

7
1 94 93 1000 92 91 90

outputFormat

Output a single integer representing the length of the longest consecutive subsequence found in the array.

Example:

5
## sample
7
1 94 93 1000 92 91 90
5