#C808. Longest K-Famous Subarray
Longest K-Famous Subarray
Longest K-Famous Subarray
Given an array of integers, your task is to determine the length of the longest contiguous subarray where all elements are identical and the subarray has a length of at least \(k\). Such a subarray is termed as a "k-famous" subarray. If no such subarray exists, output \(-1\).
For example, if the array is [1, 1, 2, 2, 2, 2, 3] and \(k=3\), the longest valid subarray is [2, 2, 2, 2] with a length of 4.
inputFormat
The input is read from standard input. The first line contains a single integer (T) representing the number of test cases. For each test case, the first line contains two integers (n) and (k), where (n) is the number of elements in the array and (k) is the minimum required length for a "k-famous" subarray. The second line contains (n) space-separated integers representing the elements of the array.
outputFormat
For each test case, output a single line with one integer which is the length of the longest "k-famous" subarray. If no such subarray exists, output -1.## sample
3
7 3
1 1 2 2 2 2 3
5 2
5 5 5 1 1
5 2
1 2 3 4 5
4
3
-1
</p>