The Magnetic Ball Distribution Challenge
In Rick's laboratory, he has discovered a unique property of magnetic force between balls placed in special baskets. Given n baskets positioned at different locations and m magnetic balls, your task is to distribute the balls optimally.
The Goal: Place m balls into m different baskets such that the minimum magnetic force between any two balls is maximized.
Magnetic Force Formula: The magnetic force between two balls at positions x and y is |x - y| (absolute difference).
Input: An integer array position representing basket locations and integer m representing number of balls.
Output: Return the maximum possible minimum magnetic force.
Example: If baskets are at positions [1, 2, 3, 4, 7] and you have 3 balls, placing them at positions [1, 4, 7] gives minimum force of 3 (distances: 3, 3, 6).
Input & Output
Constraints
- 2 โค n โค 105
- 2 โค m โค n
- 1 โค position[i] โค 109
- All positions are distinct
- m balls must be placed in m different baskets