DSA AnimatorDSA animations
Find Minimum in Rotated Sorted Array LC #153 Medium Binary Search · Rotation Pivot
Problem

Suppose an array of length n sorted in ascending order is rotated between 1 and n times. Given the rotated array nums (all unique elements), find and return the minimum element in O(log n) time.

Example 1
Input: nums = [3,4,5,1,2]
Output: 1
Original [1,2,3,4,5] rotated 3 times.
Example 2
Input: nums = [4,5,6,7,0,1,2]
Output: 0
Original [0,1,2,4,5,6,7] rotated 4 times.
Example 3
Input: nums = [11,13,15,17]
Output: 11
Not rotated — min is the first element.
Constraints: n == nums.length  |  1 ≤ n ≤ 5000  |  −5000 ≤ nums[i] ≤ 5000  |  All integers are unique.
Try Examples
Custom:
Rotated Array — Pivot Detector
State Variables
lo
—
hi
—
mid
—
nums[mid]
—
nums[hi]
—
Step Logic
Press ▶ Play or Next Step to begin the animation.
🏅
Ready
0 / 0
Select an example above and press Play.
Algorithm
1
Init lo=0, hi=n-1. The minimum is somewhere in [lo..hi].
2
Compute mid = lo + (hi-lo)/2.
3
If nums[mid] > nums[hi]: drop is in right half → lo = mid+1.
4
Else: right half sorted or same → minimum is at mid or left → hi = mid.
5
When lo == hi: nums[lo] is the minimum.
Time
O(log n)
Space
O(1)
Why It Works

A rotated sorted array has exactly one inflection point — the rotation pivot — where values drop. Comparing nums[mid] to nums[hi] tells us which half contains the drop:

nums[mid] > nums[hi]: the left half is "normally sorted" but the big values are there. The drop must be to the right.

nums[mid] ≤ nums[hi]: the right half is sorted (or equal). The minimum is at mid or further left.

We never compare to nums[lo] because the pivot could be exactly at mid.

How to solve Find Minimum in Rotated Sorted Array

LeetCode 153 · Medium · Binary Search · Pattern: Binary Search

Why the obvious approach is slow

Scanning every element is O(n). The rotation leaves two sorted runs, and the minimum is where the second run starts.

The key idea

Compare the middle with the last element of the range. If the middle is bigger, the drop happens to the right, so the minimum is on the right. Otherwise, the minimum is at mid or to its left.

Remember

Compare mid with the right end to see which side holds the drop. The minimum is the start of the second sorted run.

Run the animation above on your own input, or watch the 1:12 video explanation of Find Minimum in Rotated Sorted Array with a dry run and Java code.

More Binary Search problems