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,
1,
2
],
"k": 3
}
Execution steps
Look up matching prefix
Computed output
3
JavaScript reference implementation
const solve = ({
a,k
},s)=>{
let m=new Map([[0,1]]),v=0,c=0;
a.forEach((x,i)=>{
v+=x;
c+=m.get(v-k)||0;
m.set(v,(m.get(v)||0)+1);
s("Look up matching prefix",{
Array:a,Prefix:[v],Count:[c],Map:[...m].map(x=>x.join(":"))
},[i])
});
return c
};