Closest Numbers

  • + 0 comments

    def closestNumbers(arr):

    arr.sort()
    dc = {}
    min_i = float('inf')
    for i in range(1, len(arr)):
        if abs(arr[i]-arr[i-1]) == min_i:
            dc[min_i] += arr[i-1],arr[i]
        if arr[i]!=arr[i-1] and abs(arr[i]-arr[i-1]) < min_i:
            min_i = abs(arr[i]-arr[i-1])
            dc[min_i]= arr[i-1],arr[i]
    return dc[min_i]