All test cases showing wrong.Aggressive cows Problem

#include
using namespace std;

bool canPlaceCows(int *stalls,int n,int c,int min_sep)
{
int last_cow=stalls[0];
int count=1;
for(int i=1;i<n;i++)
{
if(stalls[i]-last_cow>=min_sep)
{
last_cow=stalls[i];
count++;
if(count==c)
return true;
}
}
return false;
}

int main()
{
int N,C;
cin>>N>>C;

int *stalls=new int[N];
for(int i=0;i<N;i++)
   cin>>stalls[i];

int l=0;
int h=stalls[N-1]-stalls[0];

int ans=0;
while(l<=h)
{
    int mid=(l+h)/2;
    
    bool cowsRakhPaaye=canPlaceCows(stalls,N,C,mid);
    if(cowsRakhPaaye)
    {
        ans=mid;
        l=mid+1;
    }
    else
       h=mid-1;
}
cout<<ans;

}

@Mukul-Shane-1247687648773500,
code is correct just sort the array (if u r using binary search don’t forget its main step)

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.

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.