Magnetic Force Between Two Balls
Medium
Topics
Given an array nums of distinct basket positions and an integer target (= m balls), place the balls into baskets so that the minimum distance between any two balls is as large as possible. Return that maximum possible minimum distance.
Example 1
Input: nums = [1,2,3,4,7], target = 3 Output: 3
Example 2
Input: nums = [5,4,3,2,1,1000000000], target = 2 Output: 999999999
Constraints
- 2 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^9
- All positions are distinct.
- 2 <= target <= nums.length
Run ⌘' · Submit ⌘⏎