# Only partial tests are passed, why?

#1

long long int BS(vectorarr,long long int l,long long int h,long long int k){
long long int mid;
while(l<=h){
mid=(l+h)/2;
if(arr[mid]==k){
return mid;
}
if(arr[mid]>k){
h=mid-1;
}
else{
l=mid+1;
}
}
return -1;
}

long long int findPivot(vector arr,long long int n,long long int l,long long int h){
while(l<=h){
long long int mid=(l+h)/2;
if(mid==n-1){
break;
}
if(arr[mid]>arr[mid+1]){
return mid;
}
else{
l=mid+1;
}
}
return -1;
}

int Solution::search(const vector &A, int B) {

``````long long int pivot=findPivot(A,A.size(),0,A.size()-1);
if(pivot == -1){
return BS(A,0,A.size()-1,B);
}

long long int ans =-1;

if(BS(A,0,pivot,B)!= -1){
return BS(A,0,pivot,B);
}

if(BS(A,pivot+1,A.size()-1,B)!= -1){
return BS(A,pivot+1,A.size()-1,B);
}

return ans;
``````

}

#2

always remember that array is rotated.
int next=(mid+1)%n;
int prev=(mid+n-1)%n;
you have to compare the arr[mid] with next nd previous nd above method should be used to find next nd previous element.
because supose if mid is at last element then next will be 0th index bcz the array is rotated.