We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Closest Numbers
You are viewing a single comment's thread. Return to all comments →
def closestNumbers(arr):