Magnetic Force Between Two Balls

In the universe Earth C-137, Rick discovered a special form of magnetic force between two balls when placed in his new invented basket. There are n empty baskets at different positions. Given m balls, the task is to distribute them into the baskets such that the minimum magnetic force between any two balls is maximized. The magnetic force between two balls at positions x and y is the absolute difference between the positions, |x - y|. The solution should return the required maximum possible minimum magnetic force.

Constraints

  • n == position.length
  • 2 <= n <= 100000
  • 1 <= position[i] <= 1000000000
  • All integers in position are distinct.
  • 2 <= m <= position.length
Saving… · 2 lines
class Solution:
def magneticForceBetweenTwoBalls(self, position: List[int], m: int) -> int:
Console

Click Run to execute sample tests.