All submissions for this problem are available.
Zebi is having a nice day in her class, when Zikon comes to her and starts bragging about how he solved the three problems in codewars which others could not. Zebi tried not to react but when she could not tolerate, she challenged him to solve another problem on arrays. Zikon, being immersed in his pride accepted her challenge.
Zebi gives Zikon an array of integers and a number k (not more than length of array). Now Zikon has to print the length of longest subarray in which the distance between repeating elements is atleast k.
Zikon can’t come up with an optimal solution and asks you for help.
First line contains an integer T, number of test cases.
For each test case
- First line contains two space separated integers n (size of array) and k.
- Next line contains n space separated integers.
- Print the length of longest subarray satisfying the requirements and -1 if no such subarray exists.
- 1 ≤ T ≤ 10
- 1 ≤ n ≤ 105
- 1 ≤ k ≤ n-1
- 1 ≤ ai ≤ 105
Input: 2 5 2 1 2 3 4 5 6 3 2 3 2 4 1 3 Output: 5 5
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5|
Fetching successful submissions
If you are still having problems, see a sample solution here.