
Consider 0-based indexing of the array.
Input : arr[] = {5, 1, 3, 4, 3}, X = 3
Output : 2
There are two instances of 3 in the array - 2 and 4. Since we need to return the first instance our result is 2.
The first line contains a single integer ‘T’ representing the number of test cases.Then ‘T’ test cases follow.
The first line of each test case contains the integer ‘N’ and ‘X’ representing the size of the input ‘ARR’ and the integer to be searched.
The next line of each test case contains ‘N’ single space-separated integers that represent the elements of the ‘ARR’.
For each test case, return the leftmost occurrence of integer X or -1.
You don’t need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 10^5
0 <= ARR[i] <= 10^9
Time Limit: 1 sec
Approach: