First Come First Serve
Submissions: 2143   Accuracy:

49.6%

  Difficulty: Basic   Marks: 1

CodeMart is an online shopping platform and it is distributing gift vouchers to its esteemed users. The voucher can be redeemed by providing a fixed amount of shopping credits.Each credit is sent by a user one by one. Since there is a huge rush of people you are required to manage the users on the basis of first come first serve. The user which comes first and has k occurrences of credits is given the voucher first. You are given an array with the id's of the users in chronological order of the credits sent by them. You are required to print the id of the user which will be served first. If no such user meets the condition print "-1".    

Input:
The first line of input contains an integer T denoting the number of test cases. Each test case contains two integers n and k where n denoted the number of elements in the array a[]. Next line contains space separated n elements in the array a[].

Output:
Output a single integer which is the number of first k occurrences. Output "-1" if no such number exists.

Constraints:
1<=T<=10
1<=n<=1000
1<=a[i]<=100000
1<=k<=100

Example:
Input:

2
7 2
1 7 4 3 4 8 7
6 1
4 1 6 1 6 4
Output:
7
-1

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

Contributor: Shashwat Jain
Author: shashwat jain


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.