Problems/

Find Minimum in Rotated Sorted Array

medium

An ascending sorted array of distinct integers has been rotated between 1 and n times. For example, [0,1,2,4,5,6,7] rotated 4 times becomes [4,5,6,7,0,1,2].

Given the rotated array nums, return its minimum element in O(log n) time.

Example 1

Input: nums = [3,4,5,1,2]
Output: 1

Example 2

Input: nums = [4,5,6,7,0,1,2]
Output: 0

Example 3

Input: nums = [11,13,15,17]
Output: 11
Explanation: rotating n times leaves the array sorted.

Constraints

  • 1 <= nums.length <= 5000
  • All integers are distinct.

Input

nums = [3,4,5,1,2]

Expected

1

5 hidden tests run on submit