Minimum Absolute Difference in an Array

  • + 0 comments

    Here is my c++ solution, you can find the explanation here : https://youtu.be/6SnD7A1TbJQ

    int minimumAbsoluteDifference(vector<int> arr) {
        sort(arr.begin(), arr.end());
        int result = INT_MAX;
        for(int i = 1; i < arr.size(); i++){
            int d = arr[i] - arr[i-1];
            if( d < result) result = d;
        }
        return result;
    }