-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBS_DroppedSensorMetric.cpp
72 lines (63 loc) · 1.27 KB
/
BS_DroppedSensorMetric.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
https://binarysearch.com/problems/Dropped-Sensor-Metric
Dropped Sensor Metric
*/
int solve__(vector<int>& a, vector<int>& b) {
int n = a.size();
int i=0, j=0, dropped;
for(int k=0; k<n-1; k++)
{
if(a[i]==b[j])
{
i++, j++;
}
else if(a[i]<b[j] && a[i+1]==b[j])
{
dropped = a[i];
i++;
}
else if(a[i]<b[j] && a[i]==b[j+1])
{
dropped = b[j];
j++;
}
else if(a[i]>b[j] && a[i+1]==b[j])
{
dropped = a[i];
i++;
}
else if(a[i]>b[j] && a[i]==b[j+1])
{
dropped = b[j];
j++;
}
}
return dropped;
}//end
int solve(vector<int>& a, vector<int>& b) {
int l=0, mid;
int h=a.size()-1;
while(l<h)
{
mid = l + (h-l)/2;
if(a[mid]==b[mid])
l = mid+1;
else
h = mid;
}
if(a[l+1]==b[l])
return a[l] ;
else
return b[l];
// for(int i=0; i<a.size(); i++)
// {
// if(a[i]!=b[i])
// {
// if(b[i] == a[i+1])
// return a[i];
// else
// return b[i];
// }
// }
// return 0;
}//end