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.
n_arr = []
arr.sort()
for i in range(len(arr) - 1):
c = arr[i]
n = arr[i + 1]
d = abs(c - n)
n_arr.append((c, n, d))
m = min([i[2] for i in n_arr])
return [f'{i[0]} {i[1]}' for i in n_arr if i[2] == m]
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):