Class Solution
java.lang.Object
g2601_2700.s2616_minimize_the_maximum_difference_of_pairs.Solution
2616 - Minimize the Maximum Difference of Pairs.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>p</code>. Find <code>p</code> pairs of indices of <code>nums</code> such that the <strong>maximum</strong> difference amongst all the pairs is <strong>minimized</strong>. Also, ensure no index appears more than once amongst the <code>p</code> pairs.</p>
<p>Note that for a pair of elements at the index <code>i</code> and <code>j</code>, the difference of this pair is <code>|nums[i] - nums[j]|</code>, where <code>|x|</code> represents the <strong>absolute</strong> <strong>value</strong> of <code>x</code>.</p>
<p>Return <em>the <strong>minimum</strong> <strong>maximum</strong> difference among all</em> <code>p</code> <em>pairs.</em> We define the maximum of an empty set to be zero.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [10,1,2,7,1,3], p = 2</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong></p>
<p>The first pair is formed from the indices 1 and 4, and the second pair is formed from the indices 2 and 5.</p>
<p>The maximum difference is max(|nums[1] - nums[4]|, |nums[2] - nums[5]|) = max(0, 1) = 1. Therefore, we return 1.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [4,2,1,2], p = 1</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong></p>
<p>Let the indices 1 and 3 form a pair. The difference of that pair is |2 - 2| = 0, which is the minimum we can attain.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>
<li><code>0 <= p <= (nums.length)/2</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimizeMax
public int minimizeMax(int[] nums, int p)
-