Code AnalysisBeginner 50s
Trace: Binary Search Steps
How many loop iterations run?
Starter code
let lo=0,hi=15,target=11,steps=0;
while(lo<=hi){let mid=(lo+hi)>>1;steps++;
if(mid===target)break;
if(mid<target)lo=mid+1;else hi=mid-1;}
console.log(steps)Think you can answer under pressure?
Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.