Find Minimum in Rotated Sorted Array
Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2].
Given the sorted rotated array nums of unique elements, return the minimum element of this array.
You must write an algorithm that runs in **O(log n)** time.
Examples
nums = [3,4,5,1,2]1nums = [4,5,6,7,0,1,2]0nums = [11,13,15,17]11Constraints
n == nums.length1 <= n <= 5000-5000 <= nums[i] <= 5000All integers are unique
š” Hints
Hint 1
The minimum is at the rotation point.
Hint 2
If nums[mid] > nums[right], the min is in the right half.
Hint 3
Otherwise, the min is in the left half (including mid).
Algorithm Complexity
Official asymptotic Big-O runtime and auxiliary memory analysis
Binary search for the inflection point. If nums[mid] > nums[right], the minimum is in the right half. Otherwise, it's in the left half (including mid).
Binary search eliminates half of the search interval at each step by comparing nums[mid] with nums[right].
Only requires constant auxiliary index variables (left, right, mid).
š Real-World Use Cases
Detecting the oldest entry in a circular log buffer ā finding the rotation point to identify the earliest timestamp.
š Dry Run
Find minimum in [3,4,5,1,2]. Initialize left=0, right=4.