Why are we taking e as :
e= stalls[n-1] -stalls[0] and not e= stalls[n-1] , why can’t we place cow at last position in array ?
Aggressive Cows
Hi @dhanshree_p18 , why we did e=stalls[n-1] -stall[0]??
here we need to find the maximum distance two cows can have between them and we are using binary search to find the answer .here s and e denotes the range between the answer exists, we choose e as stalls[n-1] - stall[0] because the distance between two cows will be maximum when one cow is at starting stall and other at ending stall and distance between two stall is stalls[n-1]-stall[0] (which is possible in case there are two cows)
In case of any doubt feel free to ask
if you got the answer then mark your doubt as resolved
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.