mediumBinary SearchPure DSA~20 min
Find The Minimum In A Rotated Sorted Ring
A sorted list of distinct version numbers was rotated at an unknown pivot. Locate the smallest value (the rotation point) in O(log n).
Problem
Given a rotated ascending array of distinct integers nums, return its minimum element. Run in O(log n).
Input
A rotated sorted integer array nums with distinct values.
Output
The minimum element.
Constraints
- 1 ≤ n ≤ 5000
- -5000 ≤ nums[i] ≤ 5000
- All values distinct.
Examples
Example 1
Input
[3,4,5,1,2]
Output
1
Rotation pivot is at value 1.
Example 2
Input
[4,5,6,7,0,1,2]
Output
0
Smallest value 0 sits at the pivot.