Associated Course(s):
Must Do Interview Preparation
Sudo Placement 2019

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**.

**Input:**

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[ ].

**Output:**

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

**Constraints:**

1 <= T <= 100

1 <= N, K <= 10^{5}

1<= A <= 10^{6}

**Example:**

**Input :**

1

7 2

1 7 4 3 4 8 7

**Output :**

7

**Explanation:**

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

Author: sujnesh

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.

Akkki111 | 38 |

SaltBaeSama | 34 |

ambercyrus | 33 |

LegendFire | 32 |

chocozz | 32 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1219 |

mazumderrohit8 | 1095 |

SumitSingh27 | 1090 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4566 |

Quandray | 4444 |

Login to report an issue on this page.