Problem · Array

Maximize the Minimum Cone Distance

Learn this problem
MediumSumo Logic logoSumo LogicFULLTIMEPHONE SCREEN

Problem 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) → int

Examples

Example 1

positions = [1,2,8,4,9]m = 3return = 3

Choosing 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 = 8

Choosing [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 positions are distinct.
drafts saved locally
public int maximizeMinimumConeDistance(int[] positions, int m) {
    // Return the largest feasible minimum gap.
}
positions[1,2,8,4,9]
m3
expected3
checking account