Sorting is useful as the first step in many different tasks. The most common task is to make finding things easier, but there are other uses as well. In this case, it will make it easier to determine which pair or pairs of elements have the smallest absolute difference between them.
Sorted, . Several pairs have the minimum difference of : . Return the array .
As shown in the example, pairs may overlap.
Given a list of unsorted integers, , find the pair of elements that have the smallest absolute difference between them. If there are multiple pairs, find them all.
Complete the closestNumbers function in the editor below.
closestNumbers has the following parameter(s):
int arr[n]: an array of integers
- int: an array of integers as described
The first line contains a single integer , the length of .
The second line contains space-separated integers, .