#K55517. Longest Consecutive Subsequence

    ID: 29993 Type: Default 1000ms 256MiB

Longest Consecutive Subsequence

Longest Consecutive Subsequence

Given an array of integers, find the length of the longest consecutive subsequence. A consecutive subsequence is defined as a sequence of numbers where each number is one greater than the previous one. For example, in the array [100, 4, 200, 1, 3, 2, 102, 103, 104], the longest consecutive subsequence is [1, 2, 3, 4] which has a length of 4.

In mathematical terms, if we denote the array as (A) and a valid consecutive subsequence starting at (a) is a sequence (a, a+1, a+2, \ldots, a+k), then the goal is to find the maximum (k+1) such that all these elements exist in (A).

inputFormat

The input is provided via standard input (stdin) as a single line containing space-separated integers representing the array.

outputFormat

Print a single integer to standard output (stdout) representing the length of the longest consecutive subsequence found in the array.## sample

100 4 200 1 3 2 102 103 104
4