Widest spacing for k sensors
A straight rail has mounting points at the distinct integer positions in spots, listed in no particular order. You must mount k sensors, each at a different point. Sensors that are close interfere, so you want the smallest distance between any two of them to be as large as possible. Return that largest possible smallest distance.
Constraints: 2 <= k <= len(spots), 0 <= spots[i] <= 10^9. Aim for O(n log n + n log R), where R = max(spots) − min(spots): trying every distance one at a time is O(n · R).
Besides the tests, one large input (1,000 spots, k = 500) with a ~150 ms limit (scaled to your device's speed): brute force won't pass.
Examples
widest_spacing([1,2,3,4,7], 3)→3widest_spacing([5,4,3,2,1,1000000000], 2)→999999999widest_spacing([1,2,8,4,9], 3)→3