8. Find Minimum in Rotated Sorted Array

Medium · Array

A sorted array of unique integers has been rotated at an unknown pivot index. For example, [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]. Find the minimum element in the rotated array.

You must solve this in O(log n) time complexity.

Examples

Example 1
Input: [3,4,5,1,2]
Output: 1
Explanation: The array was originally [1,2,3,4,5], rotated at index 3. The minimum element is 1.
Example 2
Input: [2,1]
Output: 1
Explanation: The array was rotated at index 1. The minimum element is 1.

Constraints