You are viewing a single comment's thread. Return to all comments →
JS:
function maxMin(k, arr) { const sortedArr = arr.sort((a,b)=>a-b); let min = Infinity; for (let i = 0; i + k <= sortedArr.length; i++){ const diff = sortedArr[i + k - 1] - sortedArr[i]; if (diff < min) min = diff; if (min === 0) return min; } return min; }
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 →
JS: