How do we decide that we need to use binary search in this problem? This thing is eating me up since I viewed this problem
Problem in aggressive cows question
See here, you are given some positions and some cows. And you need to find the some distance at which it is safe to place them.
If you understand the problem and what we need to find in it then
Here you can also find that distance linearly searching (or you can say Brute force) by selection start and end of the range and trying out all the possibilities. But the problem will be the time complexity.
So we can need to reduce the time complexity, and the conditions for applying Binary search is the data or range must be sorted. So here we can easily apply that.
Also these things will come from practice, do more and more questions on binary search if you are facing issues and you will good to go.
I hope this will help you somewhere in understanding the reason.
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.