forked from srinathr91/TestJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSriNatg.java
More file actions
53 lines (47 loc) · 952 Bytes
/
SriNatg.java
File metadata and controls
53 lines (47 loc) · 952 Bytes
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
43
44
45
46
47
48
49
50
51
52
53
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class SriNatg {
static int search(List<Integer>a,int b){
int start=0;
int end=a.size()-1;
int result=-1;
int index=-1;
if(b<a.get(0)){
return start;
}
else if(b>a.get(end)){
return end+1;
}
while(start<=end){
index=start+((end-start)/2);
if(a.get(index)==b){
result=index;
end=index-1;
}
else if(a.get(index)>b){
end=index-1;
}
else{
start=index+1;
}
}
//System.out.println("res= "+result);
if(result==-1){
//System.out.println("alam"+end);
return end+1;
}
return result;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
List<Integer> ip = new ArrayList<>();
while(sc.hasNextInt()){
ip.add(sc.nextInt());
}
//System.out.println(ip.size());
System.out.println(search(ip,8));
sc.close();//tr
// TODO Auto-generated method stub
}
}