Challenge I

4.2

4 votes
Binary Search, Easy
Problem

You are given an array A of n distinct sorted numbers. You are also given m queries of the form x. Your task is to output the index of the number x within the array. If x is not within the array output -1.

Constraints

The values in the array will range from -10^9 to 10^9.
1 <= n <= 10^5
1 <= m <= 10^5

Input and Output

The input consists of n on the first line followed by the array on the next.
After that m on the next line followed by m queries.
For each of the m queries, print on a seperate line, the index of the number in the array or -1 if the number is not in the array.

Sample Input
5
1 2 3 7 10
3
1
2
4
Sample Output
0
1
-1
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?