Skip to content

Latest commit

 

History

History
21 lines (18 loc) · 428 Bytes

max-min.MD

File metadata and controls

21 lines (18 loc) · 428 Bytes

Max Min (HackerRank)

https://www.hackerrank.com/challenges/angry-children


// Complete the maxMin function below.
int maxMin(int k, vector<int> arr) {
    int min = INT_MAX;
    sort(arr.begin(), arr.end());

    cout << k << endl;
    for (int i = k - 1; i < arr.size(); ++i) {
        int temp = arr[i] - arr[i - k + 1];
        if (temp < min) {
            min = temp;
        }
    }
    return min;
}