/153. Find Minimum in Rotated Sorted Array

153. Find Minimum in Rotated Sorted Array

Medium
Arrays53.9% acceptance

Given an array rotated_sorted_array of length n, which was originally sorted in strictly increasing order and then rotated between 1 and n times, return the minimum element. All elements are unique. The solution must run in O(log n) time.

Example 1

Input: [8,9,10,2,3,4,5,6,7]

Output: 2

Explanation: Original array was [2,3,4,5,6,7,8,9,10], rotated 3 times.

Example 2

Input: [22,23,24,25,26,27,28,20,21]

Output: 20

Explanation: Original array was [20,21,22,23,24,25,26,27,28], rotated 7 times.

Example 3

Input: [100,200,300,400,500]

Output: 100

Explanation: Original array was [100,200,300,400,500], rotated 5 times.

Constraints

  • 1 <= len(rotated_sorted_array) <= 5000
  • -5000 <= rotated_sorted_array[i] <= 5000
  • All elements in rotated_sorted_array are unique
  • rotated_sorted_array is a sorted array rotated between 1 and n times
Python (current runtime)

Case 1

Input: [15,16,17,18,19,10,11,12,13,14]

Expected: 10

Case 2

Input: [50,60,70,80,90,10,20,30,40]

Expected: 10

Case 3

Input: [1,2,3,4,5,6,7,8,9,10]

Expected: 1

Case 4

Input: [5,6,7,8,9,1,2,3,4]

Expected: 1

Case 5

Input: [3000,4000,5000,1000,2000]

Expected: 1000