Class Solution
java.lang.Object
g1501_1600.s1552_magnetic_force_between_two_balls.Solution
1552 - Magnetic Force Between Two Balls.<p>Medium</p>
<p>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 <code>n</code> empty baskets, the <code>i<sup>th</sup></code> basket is at <code>position[i]</code>, Morty has <code>m</code> balls and needs to distribute the balls into the baskets such that the <strong>minimum magnetic force</strong> between any two balls is <strong>maximum</strong>.</p>
<p>Rick stated that magnetic force between two different balls at positions <code>x</code> and <code>y</code> is <code>|x - y|</code>.</p>
<p>Given the integer array <code>position</code> and the integer <code>m</code>. Return <em>the required force</em>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/08/11/q3v1.jpg" alt="" /></p>
<p><strong>Input:</strong> position = [1,2,3,4,7], m = 3</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> Distributing the 3 balls into baskets 1, 4 and 7 will make the magnetic force between ball pairs [3, 3, 6]. The minimum magnetic force is 3. We cannot achieve a larger minimum magnetic force than 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> position = [5,4,3,2,1,1000000000], m = 2</p>
<p><strong>Output:</strong> 999999999</p>
<p><strong>Explanation:</strong> We can use baskets 1 and 1000000000.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == position.length</code></li>
<li><code>2 <= n <= 10<sup>5</sup></code></li>
<li><code>1 <= position[i] <= 10<sup>9</sup></code></li>
<li>All integers in <code>position</code> are <strong>distinct</strong>.</li>
<li><code>2 <= m <= position.length</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxDistance
public int maxDistance(int[] position, int m)
-