K-th distinct element
Submissions: 744   Accuracy:

36.07%

  Difficulty: Basic   Marks: 1

Given an array of N integers, write a program to print K-th distinct element in the array. The given array may contain duplicates and the output should print K-th element among all unique elements. If K is more than number of distinct elements, print -1.

Input:
First line of input contains a single integer T which denotes the number of test cases. First line of each test case contains two space separated integers N and K. Second line of each test case contains N space separated integers.
Output:
For each test case, print the K-th distinct element as described above.

Constraints:
1<=T<=100
1<=N<=100000
1<=K<=100

Example:
Input:
3
6 2
1 2 1 3 4 2
6 3
1 2 50 10 20 2
4 2
2 2 2 2
Output:
4
10
-1

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

Contributor: Harsh Agarwal
Author: harsh.agarwal0


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.