You are viewing a single comment's thread. Return to all comments →
c++
int maxMin(int k, vector<int> arr) { std::sort(arr.begin(), arr.end()); int min, max, dif; dif = arr[arr.size() - 1] - arr[0]; for (int i = 0; i <= arr.size() - k; i++) { min = arr[i]; max = arr [i + k - 1]; if (max - min <= dif) { dif = max - min; } } return dif; }
Seems like cookies are disabled on this browser, please enable them to open this website
Max Min
You are viewing a single comment's thread. Return to all comments →
c++