You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
int minimumDifference(vector<int>& nums, int k) { // Pick the scores of any k students from the array so that the difference between the highest and the lowest of the k scores is minimized.
// sort -> closest elements come together
sort(nums.begin(), nums.end());
if(k==1) return 0;
// make a window of size k
vector<int> v;
int i= 0, diff;
for(i;i<k;i++) v.push_back(nums[i]); // insert fisrt k elements