Binary search test case is wrong

#include
#include
using namespace std;

int search(int *a,int m, int n)
{
int s=0;
int mid;
int e=n-1;
while(s<=e)
{
mid=(s+e)/2;
if(a[mid]==m)
{
return mid;
break;
}
else if(a[mid]>m)
{
s=mid+1;
}
else
{
e=mid-1;
}

}
return -1;
}

int main() {
int n,i,m;
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
cin>>m;

int ans=search(a,m,n);
cout<<ans;
return 0;

}

@Sajid07 Change this:
else if(a[mid]>m)
{
s=mid+1;// --> e=mid-1;
}
else
{
e=mid-1; // --> s=mid+1

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.