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
[
4,
3,
2,
6
]
Execution steps
Join two shortest ropes
Computed output
29
JavaScript reference implementation
const solve = (a,s)=>{
let c=0;
while(a.length>1){
a.sort((x,y)=>x-y);
let x=a.shift()+a.shift();
c+=x;
a.push(x);
s("Join two shortest ropes",{
Ropes:a,Cost:[c],Combined:[x]
})
}
return c
};