First element to occur k times
Submissions: 6693   Accuracy:


  Difficulty: Basic   Marks: 1
Associated Course(s):   Interview Preparation

Given an array of N integers. The task is to find the first element that occurs K number of times. If no element occurs K times the print -1.

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the size of an array and the number K. The second line of each test case contains N space separated integers denoting elements of the array A[ ].

For each test case in a new line print the required answer.

1 <= T <= 100
1 <= N, K <= 105
1<= A <= 106

Input :
7 2
1 7 4 3 4 8 7
Output :

Both 7 and 4 occur 2 times. But 7 is the first that occurs 2 times.

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

Contributor: Sujnesh Mishra
Author: sujnesh

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

to report an issue on this page.