#C13454. Longest Consecutive Difference Subsequence
Longest Consecutive Difference Subsequence
Longest Consecutive Difference Subsequence
You are given a list of integers. Your task is to find the length of the longest contiguous subsequence where the absolute difference between any two consecutive elements is exactly 1. In other words, for a valid subsequence a1, a2, ..., ak, it must hold that $$|a_{i+1} - a_i| = 1$$ for all 1 ≤ i < k.
If the list is empty, the answer is 0. Note that a single element is considered a valid subsequence with length 1.
Example: For the list [1, 2, 3, 4, 6, 7, 8, 9, 10], the longest contiguous subsequence is [6, 7, 8, 9, 10] which has length 5.
inputFormat
The input is read from standard input. The first line contains an integer n, representing the number of elements in the list. If n > 0, the next line contains n space-separated integers.
outputFormat
Output the length of the longest contiguous subsequence (subarray) where the absolute difference between each pair of consecutive elements is exactly 1. The output should be written to standard output.
## sample9
1 2 3 4 6 7 8 9 10
5
</p>