Max Min Discussions | | HackerRank

Max Min

  • + 0 comments

    c++

    int maxMin(int k, vector<int> arr) {
        int res = INT_MAX;
        std::sort(arr.begin(), arr.end());
        for(int i = 0; i + k -1 < arr.size(); ++i){
            res = std::min(res, arr[i+k-1] - arr[i]);
        }
        return res;
    }