Aggressive cow question doubt

for the given sample input,why are we placing the cows at6 1,4,8 and not 1,4,9
?
if we place at 1,4,9 the distance btw last 2 will be max

@chahatkumar
You could. But it doesn’t matter as we are supposed to print the largest minimum distance . The largest minimum distance would be the distance between Stall 1 and Stall 4 which is 3. So as long we place the third cow at any stall after Stall No. 7 , our answer would remain the same.

for the case 1,4,9 the distance btw the fisrt two cows will be 2(both excluded) and btw last two will be 4
so in this case the largest min distance will be 4.
pls tell where am i going wrong in the above case?

@chahatkumar
Do not exclude both.
Calculate as 4-1 = 3 and 9-4 = 5.
So your two distances are 3 and 5.
If we took the stalls as 1,4,8 as in example , our distances would be
4-1 = 3 and 8-4 = 4.
Distances are 3 and 4.
In both the cases , the minimum of the two distances is 3. We have to maximise this minimum distance. We have to place the cows in such a way that the two nearest cows are as far as possible.

1 Like

okay thanks :slight_smile:

@chahatkumar
Please mark this doubt as resolved in your Doubts Section if your query is solved. If you have any further doubts regarding this problem , let me know so I can help you out.