Topic: Recursion & Backtracking · Subsets and combinations
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
{
"x": 2,
"n": 10
}
Execution steps
Square base and halve exponent
Computed output
1024
JavaScript reference implementation
const solve = ({
x,n
},s)=>{
let r=1;
while(n){
if(n%2)r*=x;
x*=x;
n=Math.floor(n/2);
s("Square base and halve exponent",{
Result:[r],Base:[x],Exponent:[n]
})
}
return r
};