Problem · Array
Maximize the Minimum Cone Distance
Learn this problemProblem statement
You are given n distinct coordinates in the integer array positions. Choose exactly m coordinates at which to place cones.
The distance between two cones is the absolute difference between their coordinates. Return the largest possible value of the minimum distance between every pair of consecutively placed cones after the chosen coordinates are sorted.
Function
maximizeMinimumConeDistance(positions: int[], m: int) → intExamples
Example 1
positions = [1,2,8,4,9]m = 3return = 3Choosing coordinates [1,4,8] gives consecutive gaps 3 and 4, so its minimum gap is 3. No placement has a larger minimum gap.
Example 2
positions = [1,5,8,4,9,12,19]m = 3return = 8Choosing [1,9,19] gives gaps 8 and 10, so the answer is 8.
Constraints
2 <= positions.length <= 6000.2 <= m <= positions.length.0 <= positions[i] <= 10^9.- All coordinates in
positionsare distinct.