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,
10,
-5
]
Execution steps
Keep survivors
Resolve opposing asteroids
Computed output
[
5,
10
]
JavaScript reference implementation
const solve = (a,s)=>{
let st=[];
for(let x of a){
let ok=true;
while(ok&&x<0&&st.at(-1)>0){
if(st.at(-1)<-x)st.pop();
else if(st.at(-1)===-x){
st.pop();
ok=false
}else ok=false;
s("Resolve opposing asteroids",{
Stack:st,Incoming:[x]
})
}
if(ok)st.push(x);
s("Keep survivors",{
Stack:st
})
}
return st
};