function schedule_tasks(tasks,k){
const config = {};
tasks.forEach((task)=>{
config[task] = config[task] || 0;
config[task]++;
});
const maxHeap = new Heap([], null, ((a, b) => a[0] - b[0]));
Object.keys(config).forEach((task)=>{
maxHeap.push([config[task], task]);
})
const [max, task] = maxHeap.pop();
let intervalCount = (max - 1)*( k + 1 ) + 1;
while(maxHeap.length){
const [num, key] = maxHeap.pop();
if(num == max){
intervalCount++;
}
}
return intervalCount;
}
Type your question above this line.
Course: https://www.educative.io/collection/5668639101419520/5671464854355968
Lesson: https://www.educative.io/collection/page/5668639101419520/5671464854355968/6209895416201216