Workspace Minimum Number Of Coins
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Minimum Number of Coins visualizer

Learn Minimum Number of Coins 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 / 6Execution step
Reference example · JavaScript
Inspect reference input
{
  "coins": [
    1,
    2,
    5,
    10,
    20,
    50,
    100,
    500,
    1000
  ],
  "k": 87
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
coins,k
},s)=>{
let o=[];
for(let c of coins.sort((a,b)=>b-a))while(k>=c){
k-=c;
o.push(c);
s("Take largest fitting denomination",{
Coins:o,Remaining:[k]
})
}
return o.length
};

Execution canvas

Active Changed
STEP 1

Take largest fitting denomination

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

Coins1 items
Remaining1 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

{
  "coins": [
    1,
    2,
    5,
    10,
    20,
    50,
    100,
    500,
    1000
  ],
  "k": 87
}

Execution steps

  1. Take largest fitting denomination

Computed output

5
JavaScript reference implementation
const solve = ({
  coins,k
},s)=>{
  let o=[];
  for(let c of coins.sort((a,b)=>b-a))while(k>=c){
    k-=c;
    o.push(c);
    s("Take largest fitting denomination",{
      Coins:o,Remaining:[k]
    })
  }
  return o.length
};

Continue learning

Practice related DSA questions in the same topic.