Rick and Morty are working with a strange magnetic reaction between balls. Each basket has a fixed coordinate, and placing a ball creates magnetic force relative to other balls based on the distance between their positions.
Morty must place m balls inside n baskets, but he wants the smallest magnetic force between any two placed balls to be as large as possible.
The force between balls at coordinates x and y is:
Your task is to compute the maximum possible value of this minimum force after placing all m balls optimally.
Input: position = [2, 5, 11, 17, 21], m = 3
Output: 9
Explanation:
Place balls at positions 2, 11, 21 → forces are [9, 10], so minimum = 9. But placing at 2, 12, 22 is not possible. Optimal minimum distance = 10.
Input: position = [4, 8, 15, 16, 23, 42], m = 4
Output: 8
Explanation:
One valid placement: 4, 15, 23, 42 Minimum gap = 7.
Accepted:
Submission: