Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Guaranteed Job
0 like 0 dislike

in Online Assessments by Expert (119,150 points) | 539 views

1 Answer

1 like 0 dislike
Best answer

You are given  array b and an integer p. Find p pairs of indices of b 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

Example 2:

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

by Expert (119,150 points)

Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .