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": [
4,
5,
6,
1,
2,
3
],
"index": true
}
Execution steps
Compare midpoint with right endpoint
Computed output
3
JavaScript reference implementation
const solve = ({
a,index
},s)=>{
let l=0,r=a.length-1;
while(l<r){
let m=(l+r)>>1;
s("Compare midpoint with right endpoint",{
Array:a,Bounds:[l,m,r]
},[m,r]);
if(a[m]>a[r])l=m+1;
else r=m
}
return index?l:a[l]
};