-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFloor in a sorted array
42 lines (33 loc) · 1.07 KB
/
Floor in a sorted array
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
40
41
42
//Floor in a sorted array
import java.util.*;
import java.lang.*;
import java.io.*;
class Searching {
public static void main (String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
int t = Integer.parseInt(read.readLine());
while(t-- > 0) {
String a[] = read.readLine().trim().split("\\s+");
int n = Integer.parseInt(a[0]);
long x = Long.parseLong(a[(int)1]);
String st[] = read.readLine().trim().split("\\s+");
long arr[] = new long[n];
for(int i = 0; i < n; i++)
arr[i] = Long.parseLong(st[i]);
out.println(new Solution().findFloor(arr, n, x));
}
out.close();
}
}
class Solution{
static int findFloor(long arr[], int n, long x) {
int i;
for(i = 0; i < n; i++) {
if(arr[i] > x) {
break;
}
}
return i - 1;
}
}