Searching a number
Submissions: 31518   Accuracy:


  Difficulty: Basic   Marks: 1

Given an array of N elements and a integer K. Your task is to return the position of first occurence of K in the given array.
Note: Position of first element is considered as 1.

First line of input contains T denoting the number of testcases. For each testcase there will be two space separated integer N and K denoting the size of array and the value of K respectively. The next line contains the N space separated integers denoting the elements of array.

For each test case, print the index of first occurrence of given number K. Print -1 if the number is not found in array.

1 <= T <= 100
1 <= N <= 106
1 <= K <= 106
1 <= A[i] <= 106

Input :

5 16
9 7 2 16 4
7 98
1 22 57 47 34 18 66

Output : 

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

Author: dipjal1996

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, generate link and share the link here.

to report an issue on this page.