You are viewing a single comment's thread. Return to all comments →
#python 3 solution from itertools import pairwise def closestNumbers(arr): arr.sort() minDiff = max(arr)-min(arr) pairs = [] #finds minimum difference for i,j in pairwise(arr): minDiff = min(minDiff,j-i) #adds pairs with minimum difference to output for i,j in pairwise(arr): if j-i == minDiff: pairs.extend([i,j]) return pairs
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 →