Workspace Minimum Platforms
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Minimum Platforms visualizer

Learn Minimum Platforms with a step-by-step Greedy & Intervals visualizer, JavaScript source code and a worked example. Practice scheduling and resource allocation.

INTERACTIVE EXECUTION STUDIO
LEARN BY DOING

Predict. Execute. Understand.

Follow the source code, inspect live state changes, and predict the next operation before revealing it.

1 / 11Execution step
Reference example · JavaScript
Inspect reference input
{
  "a": [
    900,
    940,
    950,
    1100,
    1500,
    1800
  ],
  "b": [
    910,
    1200,
    1120,
    1130,
    1900,
    2000
  ]
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
a,b
},s)=>{
a.sort((x,y)=>x-y);
b.sort((x,y)=>x-y);
let i=0,j=0,c=0,max=0;
while(i<a.length){
if(a[i]<=b[j]){
c++;
i++;
max=Math.max(max,c)
}else{
c--;
j++
}
s("Process next arrival or departure",{
Arrivals:a,Departures:b,Active:[c],Peak:[max],Pointers:[i,j]
})
}
return max
};

Execution canvas

Active Changed
STEP 1

Process next arrival or departure

Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.

Arrivals6 items
Departures6 items
Active1 items
Peak1 items
Pointers2 items
Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Greedy & Intervals · Scheduling and resource allocation

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

{
  "a": [
    900,
    940,
    950,
    1100,
    1500,
    1800
  ],
  "b": [
    910,
    1200,
    1120,
    1130,
    1900,
    2000
  ]
}

Execution steps

  1. Process next arrival or departure

Computed output

3
JavaScript reference implementation
const solve = ({
  a,b
},s)=>{
  a.sort((x,y)=>x-y);
  b.sort((x,y)=>x-y);
  let i=0,j=0,c=0,max=0;
  while(i<a.length){
    if(a[i]<=b[j]){
      c++;
      i++;
      max=Math.max(max,c)
    }else{
      c--;
      j++
    }
    s("Process next arrival or departure",{
      Arrivals:a,Departures:b,Active:[c],Peak:[max],Pointers:[i,j]
    })
  }
  return max
};

Continue learning

Practice related DSA questions in the same topic.