2616. Minimize the Maximum Difference of Pairs Medium

@problem@discussion
#Array#Binary Search#Greedy



1/**
2 * [2616] Minimize the Maximum Difference of Pairs
3 *
4 * You are given a 0-indexed integer array nums and an integer p. Find p pairs of indices of nums such that the maximum difference amongst all the pairs is minimized. Also, ensure no index appears more than once amongst the p pairs.
5 * Note that for a pair of elements at the index i and j, the difference of this pair is |nums[i] - nums[j]|, where |x| represents the absolute value of x.
6 * Return the minimum maximum difference among all p pairs. We define the maximum of an empty set to be zero.
7 *  
8 * <strong class="example">Example 1:
9 * 
10 * Input: nums = [10,1,2,7,1,3], p = 2
11 * Output: 1
12 * Explanation: The first pair is formed from the indices 1 and 4, and the second pair is formed from the indices 2 and 5. 
13 * The maximum difference is max(|nums[1] - nums[4]|, |nums[2] - nums[5]|) = max(0, 1) = 1. Therefore, we return 1.
14 * 
15 * <strong class="example">Example 2:
16 * 
17 * Input: nums = [4,2,1,2], p = 1
18 * Output: 0
19 * Explanation: 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.
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	1 <= nums.length <= 10^5
25 * 	0 <= nums[i] <= 10^9
26 * 	0 <= p <= (nums.length)/2
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/minimize-the-maximum-difference-of-pairs/
32// discuss: https://leetcode.com/problems/minimize-the-maximum-difference-of-pairs/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn minimize_max(nums: Vec<i32>, p: i32) -> i32 {
38        0
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_2616() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.