 All Problems
Find Minimum in Rotated Sorted Array
medium
arrays
binary search
microsoft
amazon
facebook

Suppose an array of length n sorted in ascending order is rotated between 1 and n times. Given the rotated array nums, return the minimum element.

You must write an algorithm that runs in O(log n) time.

Example 1:

Input: 3 4 5 1 2
Output: 1

Example 2:

Input: 4 5 6 7 0 1 2
Output: 0

Constraints:

  • n == nums.length, 1 ≤ n ≤ 5000
  • -5000 ≤ nums[i] ≤ 5000
  • All integers are unique

Input format: Space-separated integers.

Output format: Minimum element.

Run to check your code against the sample cases, or submit to run every case