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,
3
],
[
2,
6
],
[
8,
10
],
[
15,
18
]
]
Execution steps
Merge or append
Computed output
[
[
1,
6
],
[
8,
10
],
[
15,
18
]
]
JavaScript reference implementation
const solve = (a,s)=>{
a.sort((x,y)=>x[0]-y[0]);
let o=[];
for(let x of a){
let l=o.at(-1);
if(l&&x[0]<=l[1])l[1]=Math.max(l[1],x[1]);
else o.push([...x]);
s("Merge or append",{
Input:a,Output:o
})
}
return o
};