Posted on

Description

Submission

class Solution {
public:
    int smallestRangeI(vector<int>& A, int K) {
        int maxVal = *max_element(A.begin(), A.end());
        int minVal = *min_element(A.begin(), A.end());
        
        int diff = abs(maxVal - minVal);
        
        if(diff <= 2 * K) return 0;
        return diff - 2 * K;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *