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
4
Execution steps
Place queens row by row
Computed output
[
[
1,
3,
0,
2
],
[
2,
0,
3,
1
]
]
JavaScript reference implementation
const solve = (n,s)=>{
let o=[];
function f(p){
s("Place queens row by row",{
Columns:p,Solutions:o
});
if(p.length===n){
o.push(p);
return
}
for(let j=0;
j<n;
j++)if(p.every((x,i)=>x!==j&&Math.abs(x-j)!==p.length-i))f([...p,j])
}
f([]);
return o
};