dn_coder
BAN USER- 0of 0 votes
AnswersGiven a list of unsorted numbers, can you find the numbers that have the smallest absolute difference between them? If there are multiple pairs, find them all.
- dn_coder in India
Sample Input
12
-20 -3916237 -357920 -3620601 7374819 -7330761 30 6246457 -6461594 266854 -520 -470
Sample Output #2
-520 -470 -20 30
Explanation
(-470)-(-520) = 30- (-20) = 50, which is the smallest difference.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a list of unsorted numbers, can you find the numbers that have the smallest absolute difference between them? If there are multiple pairs, find them all.
- dn_coder in India
Input Format
There will be two lines of input:
n - the size of the list
ar - the n numbers of the list
Output Format
Output the pairs of numbers with the smallest difference. If there are multiple pairs, output all of them in ascending order, all on the same line (consecutively) with just a single space between each pair of numbers.
Constraints
10 <= n <= 200000
-(107) <= x <= (107), x ∈ ar
Sample Input #1
10
-20 -3916237 -357920 -3620601 7374819 -7330761 30 6246457 -6461594 266854
Sample Output #1
-20 30
Explanation
30- -20 = 50, which is the smallest difference.
Sample Input #2
12
-20 -3916237 -357920 -3620601 7374819 -7330761 30 6246457 -6461594 266854 -520 -470
Sample Output #2
-520 -470 -20 30
Explanation
(-470)-(-520) = 30- (-20) = 50, which is the smallest difference.| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm