#C5474. Longest Consecutive Increasing Subsequence
Longest Consecutive Increasing Subsequence
Longest Consecutive Increasing Subsequence
You are given a sequence of integers. Your task is to find the length of the longest contiguous subsequence such that each element in the subsequence is exactly 1 greater than its previous element.
For example, given the sequence:
1 2 3 5 6 7 8
There are two increasing segments: 1 2 3
and 5 6 7 8
. The second segment has a length of 4, which is the answer.
Note: The subsequence must consist of adjacent elements in the original sequence.
inputFormat
The first line contains a single integer n, representing the number of elements in the sequence. The second line contains n space-separated integers.
outputFormat
Output a single integer, the length of the longest contiguous subsequence where each element is exactly one greater than the previous element.## sample
7
1 2 3 5 6 7 8
4
</p>