Back to questionsDSA Visualizers: 388 Coding Questions Task Scheduler visualizer Learn Task Scheduler with a step-by-step Heaps visualizer, JavaScript source code and a worked example. Practice priority queues and top k.
INTERACTIVE EXECUTION STUDIOLEARN BY DOING Predict. Execute. Understand. Follow the source code, inspect live state changes, and predict the next operation before revealing it.
1 / 9 Execution step
Prediction modePanel width Reference example · JavaScript
Inspect reference input {
"tasks": [
"A",
"A",
"A",
"B",
"B",
"B"
],
"n": 2
} Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = ({
2 tasks,n
3 },s)=>{
4 let m=new Map;
5 for (let x of tasks)m.set(x,(m.get(x)||0 )+1 );
6 let ready=new Map,slots=[],t=0 ;
7 while ([...m.values()].some(x=>x>0 )){
8 let a=[...m].filter(([x,c])=>c>0 &&(ready.get(x)||0 )<=t).sort((a,b)=>b[1 ]-a[1 ]);
9 if (a.length){
10 let x=a[0 ][0 ];
11 slots.push(x);
12 m.set(x,m.get(x)-1 );
13 ready.set(x,t+n+1 )
14 }else slots.push("idle");
15 t++;
16 s("Schedule eligible highest-frequency task",{
17 Timeline:slots,Remaining:[...m].map(p=>p.join(":"))
18 })
19 }
20 return t
21 };
Execution canvas Active ChangedSTEP 1 Schedule eligible highest-frequency task Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.
Worked example and algorithm walkthrough Topic: Heaps · Priority queues and top K
Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.
Example input {
"tasks": [
"A",
"A",
"A",
"B",
"B",
"B"
],
"n": 2
} Execution steps Schedule eligible highest-frequency task Computed output 8 JavaScript reference implementation const solve = ({
tasks,n
},s)=>{
let m=new Map;
for(let x of tasks)m.set(x,(m.get(x)||0)+1);
let ready=new Map,slots=[],t=0;
while([...m.values()].some(x=>x>0)){
let a=[...m].filter(([x,c])=>c>0&&(ready.get(x)||0)<=t).sort((a,b)=>b[1]-a[1]);
if(a.length){
let x=a[0][0];
slots.push(x);
m.set(x,m.get(x)-1);
ready.set(x,t+n+1)
}else slots.push("idle");
t++;
s("Schedule eligible highest-frequency task",{
Timeline:slots,Remaining:[...m].map(p=>p.join(":"))
})
}
return t
};Continue learning Practice related DSA questions in the same topic.