Minimum Absolute Difference in an Array

  • + 2 comments

    My Python3 solution:

    def minimumAbsoluteDifference(arr):
        
        arr.sort()
    		
        return min([abs(arr[counter+1] - arr[counter]) for counter in range(len(arr)-1)])
    

    I'm not really sure how it works, but if you sort the data structure, finding the minimum is all about comparing consectutive indexes to each other instead of to every index. After this, we do our usual absolute value and minimum value.