Minimum difference pair
Basic Accuracy: 72.43% Submissions: 5183 Points: 1

Given an unsorted array, find the minimum difference between any pair in given array.

Example 1:

Input: nums = [2, 4, 5, 9, 7]
Output: 1
Explanation: Difference between 5 and 4 is 1.

Example 2:

Input: nums = [3, 10, 8, 6]
Output: 2
Explanation: Difference between 8 and 6 is 2.


Your Task:
You don't need to read or print anything. Your task is to complete the function minimum_difference() which takes the array as input parameter and returns the minimum difference  between any pair in given array.

Expected Time Compelxity: O(N* log(N)) where N is length of array.
Expected Space Complexity: O(1)


2 <= N <= 105
1 <= nums[i] <= 109

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Minimum difference pair

Output Window