Fixed adjacent values
Given an array of integers where each element is obtained by adding either +1 or -1 to the previous element you need to find an element index with the minimum number of comparisons.
If the element is present multiple times then print the smallest index. If the element is not present print -1.
Input Format
int N, denoting the number of elements. int T, denoting the number of queries. N space separated elements, denoting the array to search. T lines, each containing the number to find.
Constraints
10<=N<=10^6
1<=T<=100
Each element fits the int32 representation.
Output Format
T lines, each containing the corresponding 0-based index of the searched element. The smallest if multiple elements with the same index exist. -1 if such element does not exist.
Sample Input 0
10 4
3 4 5 6 5 4 5 6 7 8
5
6
8
10
Sample Output 0
2
3
9
-1