Learn Lemonade Change 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.
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
[
5,
5,
5,
10,
20
]
Execution steps
Give change using larger bills first
Computed output
true
JavaScript reference implementation
const solve = (a,s)=>{
let f=0,t=0;
for(let x of a){
if(x===5)f++;
else if(x===10){
f--;
t++
}else if(t){
t--;
f--
}else f-=3;
s("Give change using larger bills first",{
Bill:[x],Fives:[f],Tens:[t]
});
if(f<0)return false
}
return true
};