Closest Numbers

  • + 0 comments

    python 3 simple solution

    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)