In this problem, you are given a list of unsorted integers, A = {a1,
a2, ..., aN}
and you are to find the pair of elements that have the
smallest absolute difference between them. If there are multiple pairs,
then you should find them all.
Note, this problem is based on the Closest Numbers challenge on HackerRank.
You will be given a series of integers from standard input in the follow format:
N a_1 a_2 ... a_N
Each input array will consist of two lines:
The first line consists of the N number of elements in the array.
The second line consists of the N elements in the array separated by spaces.
For each input array, output the pairs of elements with the smallest difference. If there are multiple such pairs, then output all of the numbers in ascending order. All the numbers should be outputted on the same line with a single space between each pair of numbers. If a number appears in multiple pairs, print it once per pair.
Given the following input:
10 -20 -3916237 -357920 -3620601 7374819 -7330761 30 6246457 -6461594 266854
Your program should output the following:
-20 30
To submit your solution, you must initiate a Merge Request in your private assignments repository and assign it to the appropriate TA from the Challenge 03 - TA assignment list.
To facility the Merge Request workflow, you must do your development in its own branch:
$ cd path/to/repo # Go to your repository $ git checkout master # Make sure we are on master branch $ git pull # Make sure we have changes for GitLab $ git pull upstream master # Fetch and merge upstream changes $ git checkout -b challenge03 # Create challenge03 branch ... # Do your work $ git commit # Commit your work (can do this multiple times) $ git push -u origin challenge03 # Push branch to GitLab