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
[
2,
3,
-2,
4
]
Execution steps
Track extreme products
Computed output
6
JavaScript reference implementation
const solve = (a,s)=>{
let h=a[0],l=h,b=h;
for(let i=1;
i<a.length;
i++){
let x=a[i];
[h,l]=[Math.max(x,h*x,l*x),Math.min(x,h*x,l*x)];
b=Math.max(b,h);
s("Track extreme products",{
Array:a,Max:[h],Min:[l],Best:[b]
},[i])
}
return b
};