In a universe, Rick has n empty baskets, where the i-th basket is at position[i], and Morty has m balls. Rick wants to distribute the balls into the baskets so that the minimum magnetic force between any two balls is maximum. The magnetic force between two balls at positions x and y is |x - y|. Given the integer array position and the integer m, return the required maximum of the minimum force.
In a universe, Rick has n empty baskets, where the i-th basket is at position[i], and Morty has m balls. Rick wants to distribute the balls into the baskets so that the minimum magnetic force between any two balls is maximum. The magnetic force between two balls at positions x and y is |x - y|. Given the integer array position and the integer m, return the required maximum of the minimum force.
Example 1:
Input: {"position":[1,2,3,4,7],"m":3}
Output: 3
Constraints:
n==position.length
2≤n≤105
1≤position[i]≤109
All integers in position are distinct.
2≤m≤position.length
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"position":[1,2,3,4,7],"m":3}
Place 3 balls in 5 baskets so the closest pair of balls is as far apart as possible. Start by sorting the basket positions.