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.
def closestNumbers(arr):
arr.sort()
_min = min([arr[i+1]-arr[i] for i in range(len(arr)-1)])
pairs = [(arr[i], arr[i+1]) for i in range(len(arr)-1) if arr[i+1]-arr[i] == _min ]
return reduce(lambda a, b: a+b, pairs)
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 →
python 3 simple solution