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,
[3,4,5,1,2]
is a rotation of
[1,2,3,4,5]
. Given a rotated unique-valued array, find the minimum element in O(log n) time.
The minimum element is the only element smaller than its left neighbor — this is the pivot point where the rotation occurred. Binary search narrows down to this pivot by comparing the middle element with the rightmost element. If the middle is greater than the rightmost, the minimum must be in the right half (the unsorted part). Otherwise, the minimum is in the left half (including the middle).
Unlike searching for a target value, this binary search variant does not compare against a fixed target. Instead it compares the middle element with the right boundary to determine which side contains the rotation point. The algorithm converges to the smallest element as the search range shrinks.
Edge cases include a single-element array (return that element), an array rotated n times (back to original order — minimum is first element), and an array with two elements. The array has no duplicates (LeetCode version).
This variant of binary search uses the right boundary rather than a fixed target value. By comparing nums[mid] with nums[hi], we determine which side contains the rotation point. When nums[mid] > nums[hi], the right half has the rotation, so we move lo to mid+1. Otherwise, hi becomes mid. This simple rule guarantees convergence to the minimum.
Example Input & Output
Single element.
Minimum 0 at index 4.
No rotation, minimum is first element.
Minimum 1 is at the pivot.
Two elements, rotated once.
Algorithm Flow

Solution Approach
Binary search with right comparison: if nums[mid] > nums[hi], min is on the right; else min is on the left (or mid).
Time O(log n), Space O(1).
Best Answers
class Solution {
public int solution(int[] nums) {
int lo = 0, hi = nums.length - 1;
while (lo < hi) {
int mid = lo + (hi - lo) / 2;
if (nums[mid] > nums[hi]) lo = mid + 1;
else hi = mid;
}
return nums[lo];
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
