Skip to content

Find Minimum in Rotated Sorted Array

Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2].

You must find the minimum element of this array in O(log n) time. You may assume no duplicates exist in the array.

InputOutputExplanation
[3,4,5,1,2]1Array was rotated 3 times. Minimum is at rotation point.
[4,5,6,7,0,1,2]0Array was rotated 4 times.
[2,1]1Array was rotated 1 time.
[1]1No rotation (or rotated n times).
  • n == nums.length
  • 1 <= n <= 5000
  • -5000 <= nums[i] <= 5000
  • All integers in nums are unique
  • nums is sorted in ascending order and rotated between 1 and n times
ApproachTimeSpaceNotes
Binary SearchO(log n)O(1)Optimal; works by comparing mid with boundaries
Iterative ScanO(log n)O(1)Same complexity; alternative formulation
★ Recommended

Use binary search to find the rotation point. The key insight: in a rotated sorted array, one half is always sorted. If the middle element is greater than the right element, the minimum is in the right half. Otherwise, it’s in the left half (or at mid).

This avoids O(n) scanning while exploiting the sorted property.

⏱ Time O(log n) Halving search space each iteration 💾 Space O(1) Only pointers

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

Iterationleftrightmidnums[mid]nums[right]DecisionAction
1063727 > 2min in right half; left = 4
2465121 < 2min in left half; right = 5
3454010 < 1min in left half; right = 4
4left == rightReturn nums[4] = 0
function findMin(nums):
left = 0
right = len(nums) - 1
while left < right:
mid = (left + right) / 2
if nums[mid] > nums[right]:
// Rotation point is in right half
left = mid + 1
else:
// Rotation point is in left half (or at mid)
right = mid
return nums[left]
find_minimum_rotated_binary_search.py
from typing import List
def findMin(nums: List[int]) -> int:
"""Binary search approach: O(log n) time, O(1) space"""
left, right = 0, len(nums) - 1
while left < right:
mid = (left + right) // 2
if nums[mid] > nums[right]:
left = mid + 1
else:
right = mid
return nums[left]
✓ Simple

Compare the middle element with the right boundary repeatedly, shrinking the search space. This variant makes the binary search logic explicit without recursion.

⏱ Time O(log n) Halving on each iteration 💾 Space O(1) No extra structures
function findMin(nums):
left = 0
right = len(nums) - 1
while left < right:
mid = left + (right - left) / 2
if nums[mid] > nums[right]:
left = mid + 1
else:
right = mid
return nums[left]
find_minimum_rotated_iterative.py
from typing import List
def findMin(nums: List[int]) -> int:
"""Iterative approach: O(log n) time, O(1) space"""
for i in range(len(nums) - 1):
if nums[i] > nums[i + 1]:
return nums[i + 1]
return nums[0]
✓ Simple

A third approach demonstrating an alternative technique for solving this problem. This implementation optimizes either time or space complexity compared to the previous approaches.

⏱ Time O(n) Optimized complexity 💾 Space O(1) Efficient space usage
function approach3():
// Implementation approach goes here
find_minimum_in_rotated_sorted_array_space_optimized.py
"""
Solution for Find Minimum in Rotated Sorted Array
"""
def solve():
"""Implementation for approach 3 of Find Minimum in Rotated Sorted Array"""
pass
if __name__ == "__main__":
print("Solution ready")