#C11833. Longest Consistent Subarray
Longest Consistent Subarray
Longest Consistent Subarray
You are given a sequence of integers representing the amount of algae in each segment. Your task is to find the length of the longest continuous subarray in which the difference between the maximum and minimum values is less than or equal to a given threshold \( k \).
In other words, for a subarray \( a[l \,..\, r] \), it is considered consistent if:
\( \max\{a[l], \dots, a[r]\} - \min\{a[l], \dots, a[r]\} \le k \).
You need to compute and output the maximum length of such a subarray for each test case.
inputFormat
The first line contains an integer \( t \) representing the number of test cases.
Each test case consists of two lines:
- The first line contains two integers \( n \) and \( k \), where \( n \) is the number of segments and \( k \) is the threshold.
- The second line contains \( n \) integers, the amounts of algae in each segment.
outputFormat
For each test case, output a single integer representing the length of the longest continuous subarray that satisfies the condition, each on a separate line.
## sample2
5 2
1 3 1 2 1
7 0
4 4 4 4 4 4 4
5
7
</p>