Problem about running time


#1

int Solution::search(const vector &A, int B) {
int start = 0, end = A.size()-1; int res = -1 , mid = -1,res1=-1;
while(start<=end){
mid = start + (end - start)/2;
if(A[mid]<A[mid-1] && A[mid]<A[mid+1]){
break;
}
else if(A[mid] < A[end])
end = mid-1;
else if(A[mid] > A[start])
start = mid+1;
}
//return mid;
int first = 0, last = mid-1 , first1 = mid , last1 = A.size()-1;
if(A[A.size()-1] < B){
while(first<=last){
res = first + (last-first)/2;
if(A[res] == B)
return res;
else if(A[res] < B)
first = res+1;
else
last = res-1;
}
}
else{
while(first1<=last1){
res1 = first1 + (last1-first1)/2;
if(A[res1] == B)
return res1;
else if(A[res1]<B)
first1 = res1+1;
else
last1 = res1-1;
}
}
return -1;
}
I think the solution can be improved, but my guess is that the solution is already running under Log(N) time , as there are two separate binary searches , that’s all , the logic seems fine ,but can anyone please tell the complexity issue???