Loading...
Loading...
Loading...
A data centre has n rack positions on a line. Choose k of them for servers so that the smallest distance between any two chosen servers is as large as possible. Print that largest smallest distance.
Example
Input
5 3 1 2 8 4 9
Output
3
Try the problem first. Open one hint at a time.
Sort the positions. For a distance d, place the first server at the leftmost rack and then at each next rack that is at least d away. If you place k servers, d is possible.
A larger d is harder to satisfy, so search for the last d that works.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor