#K91912. Longest Contiguous Subsequence
Longest Contiguous Subsequence
Longest Contiguous Subsequence
You are given a sequence of integers. Your task is to determine the length of the longest contiguous subsequence in which the difference between any two consecutive elements is at most \(1\). In other words, for a given contiguous segment \(a_i, a_{i+1}, \dots, a_j\), it must hold that \(a_{k+1} - a_k \le 1\) for every \(i \le k < j\).
Note: The subsequence must be contiguous, meaning the elements appear next to each other in the sequence.
Example:
Input: 6 1 2 2 3 4 5 Output: 6
In the example above, the entire sequence satisfies the condition since the difference between consecutive numbers is at most \(1\). Thus, the answer is the length of the sequence, which is \(6\).
inputFormat
The first line of input contains an integer \(T\) representing the number of test cases. For each test case:
- The first line contains a single integer \(N\), the number of elements in the sequence.
- The second line contains \(N\) space-separated integers representing the sequence.
All input is read from standard input (stdin).
outputFormat
For each test case, output on a new line a single integer representing the length of the longest contiguous subsequence where the difference between consecutive elements is at most \(1\).
All output should be written to standard output (stdout).
## sample3
6
1 2 2 3 4 5
5
1 3 5 7 9
4
2 2 3 4
6
1
4
</p>