# Test case are too weak wrong code also accepted

#1

int binary(vectora)
{
int i=0,j=a.size()-1,mid;
while(i<=j)
{

``````    mid=(i+j)/2;
if(a[mid]<a[mid+1] && a[mid]<a[mid-1])
return mid-1;
if(a[mid]>a[0])
i=mid+1;
else
j=mid-1;

}
if(a[0]>a[a.size()-1])
return a.size()-1;
return 0;
``````

}
int se(vectora,int n,int i)
{ int m=a.size();
int l=0,r=a.size()-1,mid;
while(l<=r)
{
mid=(l+r)/2;
int t=mid;
mid=(mid+i)%m;
// cout<<t<<" "<<mid<<endl;
if(a[mid]==n)
return mid;
else if(a[mid]>n)
r=t-1;
else
l=t+1;
}
return -1;
}
int Solution::search(const vector &A, int B) {

``````int index=binary(A);
// cout<<index<<endl;
return se(A,B,index);
``````

}

Above my code accepted but it gives the wrong answer for
Input:4 3 2 1
4
Expected Output:0
but my code gives output -1 and till it accepted

It not just for this problem, it’s happens in many problems.
InterviewBit you should work on this.

#2

The input of [4 3 2 1] is not valid as any sorted array can’t be rotated to form this input. That’s why binary search code will fail in this example