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,
2,
1,
3
]
Execution steps
Merge ordered chains
Computed output
[
1,
2,
3,
4
]
JavaScript reference implementation
const solve = (a,s)=>{
function f(a){
if(a.length<2)return a;
let m=a.length>>1,l=f(a.slice(0,m)),r=f(a.slice(m)),o=[];
while(l.length||r.length){
o.push(!r.length||l.length&&l[0]<=r[0]?l.shift():r.shift());
s("Merge ordered chains",{
Left:l,Right:r,Merged:o
})
}
return o
}
return f(a)
};