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.
defminimumAbsoluteDifference(arr):# Sort the arrayarr.sort()# Initialize the minimum difference as a large numbermin_diff=float('inf')# Traverse the sorted array and find the minimum differenceforiinrange(len(arr)-1):diff=abs(arr[i]-arr[i+1])ifdiff<min_diff:min_diff=diffreturnmin_diff
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 →