https://www.interviewbit.com/problems/chain-of-pairs/
https://www.hackerrank.com/challenges/minimum-absolute-difference-in-an-array/problem?isFullScreen=true
The absolute difference is the positive difference between two values and , is written or and they are equal. If and , . Given an array of integers, find the minimum absolute difference between any two elements in the array.
Example.
There are pairs of numbers: and . The absolute differences for these pairs are , and . The minimum absolute difference is .
Function Description
Complete the minimumAbsoluteDifference function in the editor below. It should return an integer that represents the minimum absolute difference between any pair of elements.
minimumAbsoluteDifference has the following parameter(s):
int arr[n]: an array of integers
def minimumAbsoluteDifference(arr):
# Write your code here
arr.sort()
best = abs(arr[0] - arr[-1])
for v0, v1 in zip(arr, arr[1:]):
best = min(best, abs(v0-v1))
return best