#C6757. Longest Consecutive Sequence
Longest Consecutive Sequence
Longest Consecutive Sequence
You are given a list of integers. Your task is to find the length of the longest subsequence of consecutive integers present in the list. A consecutive sequence is a set of numbers where each number is exactly one greater than the previous number. Note that duplicate values should be treated as a single element and the sequence may include negative numbers.
The problem can be mathematically described as follows: Given an array \(A = [a_1, a_2, \dots, a_n]\), find the maximum length \(L\) such that there exists a subsequence \(\{x, x+1, \dots, x+L-1\}\) with every element present in \(A\).
Input/Output I/O: The input is read from standard input and the output is written to standard output.
inputFormat
The first line of input contains a single integer (n) indicating the number of elements in the array. The second line contains (n) space-separated integers representing the elements of the array. If (n=0), the array is empty.
outputFormat
Output a single integer representing the length of the longest consecutive sequence found in the array.## sample
6
100 4 200 1 3 2
4