MediumArrayBinary SearchUpdated Sep 2026

153. Find Minimum in Rotated Sorted Array

Asked at Amazon

Difficulty

Medium

Time

O(log n)

Space

O(1)

Pattern

Array

Companies

1

Problem

You are given an array of unique numbers. The array was originally sorted in increasing order, then it was rotated some number of times. A rotation moves the last element to the front, and this can happen anywhere from 1 to n times.

Because of the rotation, the array looks like two increasing runs joined together. For example, [0,1,2,4,5,6,7] rotated 4 times becomes [4,5,6,7,0,1,2]. The smallest value sits at the point where the array drops.

Return the minimum element in the array. Your algorithm must run in O(log n) time, so a plain scan over all elements is not good enough.

A sorted array with one drop

nums3451201234The drop is between index 2 (value 5) and index 3(value 1), so the minimum is 1.
The array is one sorted run followed by another. The answer is the value right after the drop.

Constraints

  • ●n == nums.length
  • ●1 <= n <= 5000
  • ●-5000 <= nums[i] <= 5000
  • ●All the integers of nums are unique.
  • ●nums is sorted and rotated between 1 and n times.

Examples

Example 1
Inputnums = [3,4,5,1,2]
Output1
WhyThe original sorted array was [1,2,3,4,5] and it was rotated 3 times. The smallest value, 1, sits right after the drop from 5 down to 1.
Example 2
Inputnums = [4,5,6,7,0,1,2]
Output0
WhyThe original array was [0,1,2,4,5,6,7], rotated 4 times. The value 0 is the smallest and it is the first element of the second increasing run.
Example 3
Inputnums = [11,13,15,17]
Output11
WhyThis array was rotated a full n times, so it is back in plain sorted order. The minimum is simply the first element, 11.

Asked At

1 companies
CompanyDifficulty
AmazonMediumView all Amazon questions →

How to Think About It

1

A linear scan finds the minimum in O(n), but binary search can do it in O(log n).

2

Think about what distinguishes the minimum element from the rest — it is the only element smaller than its predecessor.

3

Compare nums[mid] with nums[right] to decide which half contains the minimum.

4

If nums[mid] > nums[right], the minimum is in the right half. Otherwise, it is in the left half including mid.

5

The search converges when left meets right, and that position holds the minimum.

Optimal Approach

Use binary search with two pointers at the start and end. Compare nums[mid] with nums[right]. If nums[mid] is greater, the minimum must be to the right (mid + 1 to right). If nums[mid] is less than or equal, the minimum is at mid or to the left (left to mid). When left meets right, that index holds the minimum. This runs in O(log n) time and O(1) space.

Binary search toward the drop

nums3451201234leftmidrightStep 1 — mid is index 2, nums[mid] = 5, nums[right] =2. Since 5 > 2, the minimum is to the right of mid.nums3451201234leftrightStep 2 — move left to mid + 1 = 3. Now the range isjust [1, 2].nums3451201234left/rightStep 3 — left meets right at index 3, so nums[3] = 1is the minimum.if nums[mid] > nums[right]: left = mid + 1else: right = mid
Compare the middle value with the right end. That tells us which half still contains the drop.
ComplexityTime O(log n)Space O(1)Each step throws away half of the remaining range, and we only keep a few index variables.

What Trips People Up in Real Interviews

1

Ask whether the array is guaranteed to be rotated (not just sorted) — if not rotated, the first element is the answer.

2

Explain the binary search logic clearly using the comparison of mid and right pointers.

3

Mention that comparing with the left pointer instead also works but comparing with right is cleaner.

4

Discuss why there are no duplicates — duplicates would require a modified approach with O(n) worst case.

5

Edge cases: array not rotated at all, rotated by one position, only two elements.

Solution Code

O(log n) time
def findMin(nums):
    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]

Pro at DSA?

Test your skills with a real FAANG-style mock interview.

Start a Mock Interview →

Frequently Asked Questions

What is the Find Minimum in Rotated Sorted Array problem?

Given a sorted array that has been rotated at some pivot unknown to you beforehand, find the minimum element. The array contains no duplicate elements.

How do you solve Find Minimum in Rotated Sorted Array?

The optimal approach runs in O(log n) time and O(1) space. Scroll up to "Optimal Approach" for the step-by-step walkthrough, diagrams, and code in Python, C++ and Java.

What companies ask Find Minimum in Rotated Sorted Array?

Find Minimum in Rotated Sorted Array is asked at Amazon. It is a medium difficulty problem.

What are common mistakes on Find Minimum in Rotated Sorted Array?
  • Ask whether the array is guaranteed to be rotated (not just sorted) — if not rotated, the first element is the answer.
  • Explain the binary search logic clearly using the comparison of mid and right pointers.
  • Mention that comparing with the left pointer instead also works but comparing with right is cleaner.
  • Discuss why there are no duplicates — duplicates would require a modified approach with O(n) worst case.
  • Edge cases: array not rotated at all, rotated by one position, only two elements.