mediumBinary SearchAmazonMicrosoft
Rotated Low Point
A once-sorted shelf of distinct IDs was rotated by an unknown offset. Find the smallest ID in O(log n).
Given a rotated sorted array of distinct integers `nums`, return its minimum.
Choose approach
3
0lo
4
15
21
32
4hi
1/4
Narrationstep 1 of 4
Rotated sorted array: the minimum is the only element smaller than its predecessor. Compare mid to hi to decide which side holds it.
Variables
lo=0
hi=4
How to think about it
- Pick a stable reference: nums[hi] is always ≤ nums[0..inflection].
- nums[mid] > nums[hi] → mid is on the left (bigger) run; min is right of mid.
- Otherwise mid is on the right (smaller) run — min could be mid itself.
- Stop when the interval collapses.
Edge cases to catch in interview
- Already sorted (zero rotation) — mid ≤ hi branch always wins → returns nums[0].
- Single element — returned directly.
- Rotation = n/2 — binary search still converges in log n.
Examples
Example 1
1{"nums":[3,4,5,1,2],"values":[3,4,5,1,2]}
Example 2
0{"nums":[4,5,6,7,0,1,2],"values":[4,5,6,7,0,1,2]}
Example 3
11{"nums":[11,13,15,17],"values":[11,13,15,17]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed