Doubt in understanding the question?

I am not able to get the question .Please explain this question properly?? with some another test case??

@Adhyayan,

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.

I have understood the test case but still I don’t know how to approach the solution ??
i have never done this type of question which involve some optimal solution ??
what to do to tackle such type of questions???

@Adhyayan,
These are usually trick questions or simple math behind it.

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

@Adhyayan,
don’t worry. You can try to code the problem. If you are stuck, I am here to help you out.

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.