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
At each step, identify which half around mid is properly sorted by comparing endpoints. If the target falls within the sorted half, search there. Otherwise, search the other half. One half is always sorted in a rotated array.
After rotation, at least one half around mid is always sorted. Checking which half is sorted lets us determine if the target falls in that range or the other half.
Updated Feb 2026