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
[
16,
17,
4,
3,
5,
2
]
Execution steps
Scan from right
Computed output
[
17,
5,
2
]
JavaScript reference implementation
const solve = (a,s)=>{
let b=-Infinity,out=[];
for(let i=a.length-1;
i>=0;
i--){
if(a[i]>=b){
b=a[i];
out.unshift(b)
}
s("Scan from right",{
Array:a,Leaders:out
},[i])
}
return out
};