-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
39 lines (36 loc) · 1 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.Scanner;
public class Main {
static int search(int arr[], int left,int right,int query) {
while (left<=right) {
int mid = left + (right - left) / 2;
if (arr[mid] == query) {
return mid;
}
if (arr[mid] < query) {
left = mid + 1;
}
else
right = mid - 1;
}
return -1;
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int m = s.nextInt();
int n = s.nextInt();
int[] arr = new int[m+1];
for(int i=0;i<m;i++) {
arr[i] = s.nextInt();
}
for (int i=1;i<=n;i++ ){
int x = s.nextInt();
int res = search(arr,0,m-1,x);
if (res==-1) {
System.out.println("not found");
}
else {
System.out.println(res);
}
}
}
}