Kth distance
Submissions: 4619   Accuracy:

34%

  Difficulty: Easy   Marks: 2

Given an unsorted array A of size N that may contain duplicates. Also given a number K which is smaller than size of array. Find if array contains duplicates within k distance.

Input:
The first line of input contains an integer T denoting the number of test cases. The first line of each test case is K and N, K is the distance and N is the size of array. The second line of each test case contains N elements.

Output:
Print "True" if array contains duplicates within k distance else False.

Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 106
1 ≤ K ≤ N
1 ≤ A[i] ≤ 107

Example:
Input:

4
3 8
1 2 3 4 1 2 3 4
3 6
1 2 3 1 4 5
3 5
1 2 3 4 5
3 5
1 2 3 4 4

Output:
False
True
False
True

Explanation:
Testcase 1:
1 is present twice in subarray starting from 1 (0-based index) and ending at 4.

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: rajatjha


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.