Plz share approach to solve this

not getting a way to solve it

@Yuganshu,

sample test case:
5 3
1 2 8 4 9

arranged in sorted order, index of stall available:
1 2 4 8 9

Now possible arrangement of 3 cows (3 is given in the question):
1 2 4 //min distance between adjacent cows = 1
1 2 8 // 1
1 2 9 // 1
1 4 8 // 3
1 4 9 // 3
1 8 9 // 1
2 8 4 // 2
…
4 8 9 // 1

The largest among all the min distance = 3.
That’s the output and our final answer.

Approach:

For this problem, fix one cow at the first position and then move ahead.

So create a minimum Distance function which basically calculates a mid point and treats that as the minimum distance to place a cow. If we have a position greater than or equal to this distance, we fix the cow at that position.

Now call another Function which takes as input the the minimum distance (or the mid point), number of cows, the array of stall positions and size of the array

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.