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.
least = max(max(arr), min(arr) * -1) * 2
arr = sorted(arr)
for i in range(0, math.ceil(len(arr) / 2)):
f = abs(arr[i] - arr[i + 1])
b = abs(arr[-(i + 1)] - arr[-(i + 2)])
if (least > min(f, b)):
least = min(f, b)
if (least == 0):
return 0
return least
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Absolute Difference in an Array
You are viewing a single comment's thread. Return to all comments →
Solution for Beginners
def minimumAbsoluteDifference(arr):