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
{
"a": [
1,
2,
3,
4,
5,
null,
6
],
"start": 1
}
Execution steps
Spread fire one edge per second
Computed output
3
JavaScript reference implementation
const solve = ({
a,start
},s)=>{
let q=[start],seen=new Set(q),d=0;
while(q.length){
s("Spread fire one edge per second",{
Tree:a,Frontier:q,Burned:[...seen],Time:[d]
});
let next=[];
for(let i of q)for(let j of [Math.floor((i-1)/2),2*i+1,2*i+2])if(j>=0&&a[j]!=null&&!seen.has(j)){
seen.add(j);
next.push(j)
}
q=next;
d++
}
return d-1
};