Problem · Array
Maximize the Minimum Distance Between Robots
Learn this problemProblem statement
A factory line has candidate robot stations at the distinct integer coordinates in positions. Choose exactly robots stations.
The separation of a placement is the minimum absolute distance between any two selected stations. Return the largest separation that can be achieved.
Function
maximizeMinimumRobotDistance(positions: int[], robots: int) → intExamples
Example 1
positions = [1,2,8,12,17]robots = 3return = 7Stations 1, 8, and 17 give adjacent gaps 7 and 9, so the minimum is 7.
Example 2
positions = [5,9]robots = 2return = 4Both stations must be selected, and their distance is 4.
Example 3
positions = [0,3,4,7,10]robots = 4return = 3Selecting 0, 3, 7, and 10 achieves a minimum gap of 3.
Constraints
2 <= positions.length <= 100000.2 <= robots <= positions.length.0 <= positions[i] <= 10^9.- All positions are distinct.