sorry, Tried it many times but couldn’t understand the code we are doing… can you help by an example??
Couldn't understand the problem
hello @alamsarfraz422
You first fix the minimum distance which should be maintained between adjacent cows and then use binary search to validate it, i.e. check if it is possible or not. If it is, then you can increase the minimum distance as this function is monotonic.
Now, how do you validate a particular “mid” value? Greedily. Just assign the first cow at the leftmost point and keep positioning the remaining cows as far to the right as possible while satisfying the min distance condition.