Search an Element in an array
Submissions: 32805   Accuracy:

31.7%

  Difficulty: School   Marks: 0
*School Problem's Submission isn't counted in score!
       

Given an integer array and an element x. Find if the given element is present in array or not. If present, print index of its first occurrence, else print "-1" (without quotes).

Input:
First line contains an integer, the number of test cases 'T'. For each test case, first line contains an integer 'N', size of array. The second line contains the elements of the array separated by spaces. Third line contains element to be find in the array.

Output:
For each testcase, output a single line containing first index of element to be found in array. If element is not in the array, then print "-1" (without quotes).

Constraints:
1 <= T <= 100
1 <= N <= 100
1 <= Arr[i] <= 100

Example:
Input:
1
4
1 2 3 4
3

Output:
2

Explanation:
There is one test case with array as {1, 2, 3 4} and element to be searched as 3.  Since 3 is present at index 2, output is 2

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

Author: shef5


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

to report an issue on this page.