Suppose an array of n unique integers sorted in ascending order is rotated between 1 and n times. For example, [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2] after rotating 4 times. Given the sorted rotated array nums, return the minimum element of this array. You must write an algorithm that runs in O(log n) time.
Example 1
Input: nums = [7,8,9,10,11,12,1,2,3,4,5,6]
Output: 1
Explanation: The sorted array [1,…,12] was rotated so it starts at 7. The only place where a value drops is from 12 to 1, and that 1 is the minimum.
Example 2
Input: nums = [3,4,5,1,2]
Output: 1
Explanation: The original array [1,2,3,4,5] was rotated 3 times. The drop from 5 to 1 marks the minimum, 1.
Example 3
Input: nums = [4,5,6,7,0,1,2]
Output: 0
Explanation: The original array [0,1,2,4,5,6,7] was rotated 4 times. The drop from 7 to 0 marks the minimum, 0.
In a rotated sorted array, exactly one half of any `[l, r]` window is still sorted. Compare `nums[mid]` with `nums[r]` to tell which half contains the rotation point (the minimum). - If `nums[mid] > nums[r]`, the dip lies to the **right** of mid → go right. - Otherwise, the dip is at `mid` or to the **left** → go left (keep `mid`).
Run checks all cases above. Submit evaluates all test cases.