roadmap/binary-search/Find Minimum in Rotated Sorted Array

Find Minimum in Rotated Sorted Array

MediumMicrosoftAmazonFacebookGoogle
Solve on LeetCode ↗

Given a sorted rotated array of unique integers, find the minimum element in O(log n).

The minimum is at the rotation point. Key observation: if nums[mid] > nums[hi], the minimum is in the right half (mid is in the left sorted portion, which is entirely larger). Otherwise the minimum is in the left half including mid.

Binary search on the pivot

Compare nums[mid] to nums[hi]. If mid > hi, min is in [mid+1, hi]. Otherwise min is in [lo, mid]. When lo==hi, we've found the minimum.

Time
O(log n)
Space
O(1)

Standard binary search — halves space each iteration.

Python
def findMin(self, nums: List[int]) -> int:
    lo, hi = 0, len(nums) - 1
    
    while lo < hi:
        mid = (lo + hi) // 2
        
        if nums[mid] > nums[hi]:
            lo = mid + 1  # min is in right half
        else:
            hi = mid      # min is at mid or in left half
    
    return nums[lo]
Not rotated (already sorted): nums[0] is min, algorithm handles correctly
Rotated by 1 position
Single element: return it

What pattern do you think this problem uses?

Progress is saved on this device