Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Check the middle version. If it is bad, the first bad version is at mid or earlier, so move right bound left. If good, move left bound right. Continue until pointers meet.
The answer space is monotonic: bad is false then true and never reverts. Binary search finds the first true by keeping a shrinking interval where the first bad still exists.
Updated Feb 2026