153. Find Minimum in Rotated Sorted Array¶
Edited by Charles
Medium · Python · Array
Problem
Read the original problem on LeetCode.
The official page contains the problem statement, examples, and constraints.
Explanation, examples & other approaches
Core idea
You are given a sorted array of unique elements that has been rotated between 1 and n times.
Original study notes follow, including intermediate snippets and earlier attempts.
Problem¶
You are given a sorted array of unique elements that has been rotated between 1 and n times.
For example, the original sorted array:
may become:
Return the minimum element of the array.
The solution must run in:
time.
Because the original array is sorted and all elements are unique, after rotation the array consists of two sorted parts.
For example:
The minimum element is exactly the rotation point:
We can use Binary Search to locate this point.
Key Idea¶
At every step, compare:
with:
There are two cases.
Case 1 — nums[mid] > nums[right]¶
If:
then the minimum must be strictly to the right of mid.
Example:
The drop from the larger sorted part to the smaller sorted part must occur somewhere after mid.
Therefore:
We can safely exclude mid because nums[mid] > nums[right], so mid cannot be the minimum.
Case 2 — nums[mid] < nums[right]¶
If:
then the section from mid to right is sorted:
Therefore, the minimum cannot be strictly to the right of mid.
However, mid itself may be the minimum.
Example:
Here:
and mid itself is exactly the minimum.
Therefore:
Notice that we do not use:
because doing so could accidentally remove the answer.
The rightmost element gives us a convenient way to determine which sorted section mid belongs to.
For a rotated array:
we can think of the values as:
Since nums[right] belongs to the smaller section:
means mid is still in the larger section, so we need to move right.
means mid is in the smaller section, so the minimum is at mid or somewhere to its left.
We use:
instead of:
because our search interval always contains the minimum.
We continuously shrink:
until:
At that point, only one candidate remains.
Therefore:
Consider:
Initially:
We have:
Therefore:
Now:
Now:
Therefore:
Now:
Calculate:
So:
Therefore:
Now:
So:
and:
Result:
For example:
The same algorithm still works.
Initially:
So:
We continue searching toward the left until:
and return:
No special case is required.
left = 0
right = n - 1
↓
while left < right
↓
mid = (left + right) // 2
↓
Compare nums[mid] with nums[right]
↓
┌─────────────────────────┐
│ │
↓ ↓
nums[mid] > nums[right] nums[mid] < nums[right]
minimum is strictly minimum is at mid
to the right or to the left
↓ ↓
left = mid + 1 right = mid
\ /
\ /
↓ ↓
left == right
↓
return nums[left]
This is the most important detail of this problem.
When nums[mid] > nums[right]¶
mid definitely cannot be the minimum:
There is already a smaller value at right.
Therefore:
When nums[mid] < nums[right]¶
mid could be the minimum.
Therefore, we must keep mid:
not:
Time Complexity¶
Binary Search halves the search interval each time:
Space Complexity¶
Only a few variables are used:
For LeetCode 153, remember:
Then:
Otherwise:
Finally:
and:
A compact way to remember the entire problem:
Study record
| Field | Value |
|---|---|
| Attempts | 1 |
| Mastery | ❚ |
| The Latest Attempt | September 9, 2026 |
Python solution¶
class Solution:
def findMin(self, nums: List[int]) -> int:
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]