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
],
"unique": false,
"sum": false
}
Execution steps
Record subset
Computed output
[
[],
[
1
],
[
1,
2
],
[
2
]
]
JavaScript reference implementation
const solve = ({
a,unique,sum
},s)=>{
a.sort((x,y)=>x-y);
let o=[];
function f(i,p){
o.push(sum?p.reduce((x,y)=>x+y,0):p);
s("Record subset",{
Input:a,Path:p,Output:o
});
for(let j=i;
j<a.length;
j++)if(!unique||j===i||a[j]!==a[j-1])f(j+1,[...p,a[j]])
}
f(0,[]);
return o
};