We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 60b7558 commit 0f77f88Copy full SHA for 0f77f88
1 file changed
ArraySort.java
@@ -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