TRT
Sign in
mediumCoreLeetCode#compare with the right end

Find minimum in rotated sorted array

Find the smallest element of a rotated sorted array in O(log n) by comparing the middle with the right end.

The Runtime Theory Team1 min read
Taught inRotated and two-dimensional dataPro — members onlyBinary search still works when sorted data has been rotated, because one half of any range is always sorted. Sorted grids can be searched as one long array, or with a staircase walk from a corner.
Solve it

Solving happens on the judge — come back and mark it done

Sample cases

innums = [3, 4, 5, 1, 2]

out1

innums = [4, 5, 6, 7, 0, 1, 2]

out0

innums = [11, 13, 15, 17]

out11

Given a sorted array of distinct values that has been rotated between 1 and n times, return its minimum element in O(log n).

Before you code

The minimum is right after the drop. Comparing a[mid] with a[hi] tells you which side of mid the drop is on, and also handles an array that is not rotated at all.

Hints

  1. If a[mid] > a[hi], the drop is after mid: lo = mid + 1.
  2. Otherwise a[mid..hi] is sorted and the minimum is at mid or before: hi = mid.
  3. Loop while lo < hi; the answer is a[lo].

Production & complexity notes

When solving Find minimum in rotated sorted array on LeetCode (medium), always state your loop or recursion invariant before writing code. Verify how your chosen data structure behaves on degenerate inputs (single-element inputs, all-duplicate keys, strictly monotonic sequences, or maximum constraint sizes up to $10^5$ elements). In production interviews, pair your implementation with an explicit time and auxiliary space complexity proof, explain why alternative brute-force approaches violate the latency budget, and trace how cache locality and memory allocation overhead affect wall-clock throughput on real hardware. Review the step-by-step memory trace in Rotated and two-dimensional data to reinforce the underlying pattern.

What it practices

Finding the rotation point, from Rotated and two-dimensional data.

Not started

Sign in to save your learning progress.

Sign in to save