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,
7,
8
],
[
10,
20
],
[
19,
22
]
]
Execution steps
Merge next smallest bottom node
Computed output
[
5,
7,
8,
10,
19,
20,
22
]
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("Merge next smallest bottom node",{
Lists:a,Pointers:p,Flattened:o
})
}
return o
};