Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6379
@blackshadows 6329
@mb1973 5358
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3357
@KshamaGupta 3318
Complete Leaderboard
Minimum difference pair
Basic Accuracy: 76.99% Submissions: 269 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)

 

Constraints:
1 <= N <= 105
1 <= nums[i] <= 109

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Minimum difference pair

Output Window