Find Minimum in Rotated Sorted Array
Given a sorted array of unique integers that has been rotated between 1 and n times, return the minimum element. You must run in O(log n) time.
Open official problem prompt ↗Find the pivot where the ascending order wraps around, which holds the smallest value, without scanning every element.
Like flipping through a Rolodex that someone rotated mid-way: you keep splitting the deck and asking 'did the alphabet reset in this chunk?' to home in on the single reset point.
- Input
- nums = [3, 4, 5, 1, 2]
- Output
- 1
- Why
- The array was rotated so that the smallest value 1 now sits at index 3.
n == nums.length1 <= n <= 5000-5000 <= nums[i] <= 5000All integers of nums are uniquenums is sorted and rotated between 1 and n times