1552. Magnetic Force Between Two Balls
1552. Magnetic Force Between Two Balls
Description
In the universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the i^th basket is at position[i], Morty has m balls and needs to distribute the balls into the baskets such that the minimum magnetic force between any two balls is maximum .
Rick stated that magnetic force between two different balls at positions x and y is |x - y|.
Given the integer array position and the integer m. Return the required force.
Example 1:
1 | Input: position = [1,2,3,4,7], m = 3 |
Example 2:
1 | Input: position = [5,4,3,2,1,1000000000], m = 2 |
Constraints:
n == position.length2 <= n <= 10^51 <= position[i] <= 10^9- All integers in
positionare distinct . 2 <= m <= position.length
Hints/Notes
- 2025/04/21 Q3
- binary search
- Leetcode solution
Solution
Language: C++
1 | class Solution { |