Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize the Maximum Difference of Pairs #104

Open
soniadessai opened this issue Oct 1, 2023 · 2 comments
Open

Minimize the Maximum Difference of Pairs #104

soniadessai opened this issue Oct 1, 2023 · 2 comments

Comments

@soniadessai
Copy link
Collaborator

Write code in the preferred language and attach output with it.

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.

Example 1:

Input: nums = [10,1,2,7,1,3], p = 2
Output: 1
Explanation: The first pair is formed from the indices 1 and 4, and the second pair is formed from the indices 2 and 5.
The maximum difference is max(|nums[1] - nums[4]|, |nums[2] - nums[5]|) = max(0, 1) = 1. Therefore, we return 1.

Example 2:

Input: nums = [4,2,1,2], p = 1
Output: 0
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.

@iliketrains42
Copy link

Could you please assign this to me?

@Daksha0403
Copy link
Contributor

Can u please Assign me this issue
Name-Daksha Kulkarni
C number-UCE2021437
[[email protected]]
[[email protected]] (github)
TY Comp
Cummins college of engineering pune

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants