Skip to content

Commit 0f77f88

Browse files
Array_Sort
1 parent 60b7558 commit 0f77f88

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

ArraySort.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.*;
2+
3+
public class ArraySort {
4+
static Scanner sc = new Scanner(System.in);
5+
6+
public static void main(String[] args) {
7+
int n = sc.nextInt();
8+
int[] a = new int[n];
9+
10+
for(int i = 0; i < n; i++) {
11+
a[i] = sc.nextInt();
12+
}
13+
14+
Arrays.sort(a);
15+
16+
int q = sc.nextInt();
17+
while(q-- > 0) {
18+
int x = sc.nextInt();
19+
int idx = Arrays.binarySearch(a, x);
20+
21+
System.out.println(idx < 0 ? -1 : idx + 1);
22+
}
23+
sc.close();
24+
}
25+
}

0 commit comments

Comments
 (0)