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
[
[
1,
4,
5
],
[
1,
3,
4
],
[
2,
6
]
]
Execution steps
Choose smallest remaining head
Computed output
[
1,
1,
2,
3,
4,
4,
5,
6
]
JavaScript reference implementation
const solve = (a,s)=>{
let o=[],p=a.map(()=>0);
while(true){
let b=-1;
for(let i=0;
i<a.length;
i++)if(p[i]<a[i].length&&(b<0||a[i][p[i]]<a[b][p[b]]))b=i;
if(b<0)break;
o.push(a[b][p[b]++]);
s("Choose smallest remaining head",{
Lists:a,Positions:p,Merged:o
})
}
return o
};