#K10966. Longest Contiguous Subsequence
Longest Contiguous Subsequence
Longest Contiguous Subsequence
You are given an array of N integers and an integer K. Your task is to find the length of the longest contiguous subsequence such that the difference between the maximum and minimum elements in this subsequence is at most K.
In other words, if we denote the contiguous subsequence as A[l...r], you need to ensure that:
\( \max\{A[l], A[l+1], \dots, A[r]\} - \min\{A[l], A[l+1], \dots, A[r]\} \le K \)
Your goal is to determine the maximum possible length of such a contiguous subsequence.
inputFormat
The first line of input contains two space-separated integers N and K.
The second line contains N space-separated integers representing the elements of the array.
outputFormat
Output a single integer denoting the length of the longest contiguous subsequence that meets the condition.
## sample6 3
1 3 6 7 9 10
3
</p>