Stage 1: Foundations·Binary Search Mastery
Medium#1536 min readBinary SearchRotated ArrayLeetCode

Find Minimum in Rotated Sorted Array

Compare against right boundary

Binary search on a property, not a value. Which half is sorted?

Published Apr 15, 2026

Problem

Given a rotated sorted array nums with distinct values, return the minimum element.

The array was originally sorted in ascending order, then rotated at an unknown pivot.

Input
nums = [3, 4, 5, 1, 2]
Output
1
Input
nums = [4, 5, 6, 7, 0, 1, 2]
Output
0

Intuition

The rotation creates two sorted runs. One of them contains the minimum; the other does not.

The trick is to compare the midpoint against the right boundary:

  • if nums[mid] > nums[hi], the minimum must be strictly to the right of mid;
  • otherwise, mid could be the minimum, so keep it in play by moving hi left to mid.

This is binary search on a property, not on a value. You are not asking "where is 0?" You are asking "which side of the pivot is this midpoint on?"

Approach

Binary Search on the Pivot

TimeO(log n)
SpaceO(1)
Recommended

Use a closed interval [lo, hi] with hi initialized to the last index. The minimum is always inside the interval.

  • If nums[mid] > nums[hi], the right half contains the pivot, so set lo = mid + 1.
  • Otherwise, the minimum is at mid or to its left, so set hi = mid.

When lo == hi, the interval has collapsed to the minimum.

impl Solution {
    pub fn find_min(nums: Vec<i32>) -> i32 {
        let mut lo = 0usize;
        let mut hi = nums.len() - 1;

        while lo < hi {
            let mid= lo + (hi - lo) / 2;
            if nums[mid] > nums[hi] {
                lo = mid + 1;
            } else {
                hi = mid;
            }
        }

        nums[lo]
    }
}
Rust · runnable

Trace

Find the minimum in nums = [4, 5, 6, 7, 0, 1, 2]:

lohimidnums[mid]nums[hi]action
06372move lo to 4
46512move hi to 5
45401move hi to 4

The interval collapses onto index 4, which holds the minimum 0.

Edge cases

  • Already sorted array — no rotation means the first element is the minimum.
  • One element — the loop never runs; return that element.
  • Pivot near the end — the same comparison still isolates the minimum without special cases.

Takeaway

Binary search works on structure, not just values. Once you can prove that one side of the midpoint has a property the other side lacks, the search becomes mechanical.

This exact habit reappears in answer-space binary search and in many rotated or partially ordered data problems later.

More in Binary Search Mastery