Skip to content

Practice Minimize the Maximum Difference of Pairs

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2616
LeetCode Problem

Minimize the Maximum Difference of Pairs

Problem Statement

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. 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. Return the minimum maximum difference among all p pairs. We define the maximum of an empty set to be zero.

Source: Minimize the Maximum Difference of Pairs on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [10,1,2,7,1,3], p = 2
Output
1

# Example 2

Input
nums = [4,2,1,2], p = 1
Output
0

Constraints

1 <= nums.length <= 10^5
0 <= nums[i] <= 10^9
0 <= p <= (nums.length)/2

Related LeetCode Problems

Practice more problems similar to Minimize the Maximum Difference of Pairs.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.