Find Minimum in Rotated Sorted Array explained

To find the minimum of a rotated sorted array in O(log n), binary search while comparing the middle value with the value at the right end: if the middle is larger, the drop to the minimum must be to its right, so move the left bound past it; otherwise the minimum is the middle or to its left, so pull the right bound to the middle. When the bounds meet, they sit on the minimum.

By Published 7 min read

What has happened to the array

Start with distinct numbers in increasing order. Pick a position, take everything from there to the end, and move it to the front. The result is two increasing runs, the second run all smaller than the first. The rotation may be zero, in which case the list is simply sorted. You are given only the rotated list, not the rotation amount, and must return the smallest value in logarithmic time.

Rotations of one list invented for this page; minimum found by the tested code
Rotated listMinimumWhere it sits
[15, 18, 21, 3, 7, 9]3Index 3, right after the drop
[3, 7, 9, 15, 18, 21]3Index 0, no rotation
[21, 3, 7, 9, 15, 18]3Index 1
[7, 9, 15, 18, 21, 3]3The last index
[8, 2]2Two elements, rotated
[4]4One element
Rotations of one list invented for this page; minimum found by the tested code. Scroll sideways on a small screen.

Ask whether values can repeat, since that changes the worst-case bound, and whether the list can be empty. The common version promises distinct values and at least one element.

Why it is asked

The list is not sorted, so the textbook search does not apply directly. The interviewer wants to see whether you can find a comparison that still splits the candidates cleanly in half. It is also the first step of Search in Rotated Sorted Array, so many interviewers use it as a warm-up before that one, or ask for the rotation point as a follow-up.

Baseline: look at everything

Take the minimum of the whole list, O(n). A slightly smarter linear version walks until a value is smaller than the one before it, since that drop marks the minimum, but in the worst case it still visits every element. Say that, then point out that one comparison can tell you which half holds the drop.

The comparison that splits the list

Look at the middle value and the value at the right end of the current range. If the middle is greater than the right end, the range cannot be in order from the middle to the end, so the drop is somewhere to the right of the middle, and the middle itself is not the minimum. Move low to mid + 1. If the middle is less than the right end, everything from the middle to the end is in order, so nothing to the right of the middle can be smaller than it. The minimum is the middle or something to its left. Move high to mid, keeping the middle as a candidate.

def rotated_min(values):
    low, high = 0, len(values) - 1
    while low < high:
        mid = (low + high) // 2
        if values[mid] > values[high]:
            low = mid + 1  # the drop is to the right of mid
        else:
            high = mid  # mid is in the lower run, the minimum is mid or left
    return values[low]
Python: compare with the right end, O(log n) time, O(1) space.
#include <vector>

int rotatedMin(const std::vector<int>& values) {
    int low = 0;
    int high = static_cast<int>(values.size()) - 1;
    while (low < high) {
        int mid = low + (high - low) / 2;
        if (values[mid] > values[high]) {
            low = mid + 1;
        } else {
            high = mid;
        }
    }
    return values[low];
}
C++17: the same loop, returning the value.

The loop runs while low < high, not low <= high, because the range always contains the answer and you stop when one candidate remains. Since mid is rounded down, it is always strictly less than high inside the loop, so high = mid always shrinks the range and the loop cannot stall.

Why compare with the right end, not the left

Comparing the middle with the left end sounds symmetric but is not. If the middle is larger than the left end, the left part is in order, but the minimum could be either at the very left, when there is no rotation, or somewhere past the middle. One comparison cannot tell those apart. The right end does not have that ambiguity: being smaller than the right end always means the middle sits in the lower run. You can make a left-end comparison work with an extra check for an unrotated range, but the right-end version is shorter and easier to defend.

Trace

[15, 18, 21, 3, 7, 9]
lowhighmidvalues[mid]values[high]Move
05221921 > 9, so low = 3
354797 < 9, so high = 4
343373 < 7, so high = 3
33Stop: the minimum is 3
[15, 18, 21, 3, 7, 9]. Scroll sideways on a small screen.

Follow-up: repeated values

If values can repeat, the middle and the right end can be equal, and then you cannot tell which side the drop is on. In [6, 1, 6, 6, 6] and [6, 6, 6, 1, 6] the middle (index 2) and the right end are both 6, yet the minimum sits at index 1 in the first list and index 3 in the second. The safe move is to drop the right end by one: since it equals the middle, discarding it cannot lose the minimum's value. Distinct comparisons still halve the range, but a list made mostly of one repeated value forces one step at a time, so the worst case becomes O(n). Say so plainly; no comparison-based method can do better in that case.

def rotated_min_with_repeats(values):
    low, high = 0, len(values) - 1
    while low < high:
        mid = (low + high) // 2
        if values[mid] > values[high]:
            low = mid + 1
        elif values[mid] < values[high]:
            high = mid
        else:
            high -= 1  # cannot tell which side; drop one copy safely
    return values[low]
Repeated values allowed: shrink by one on a tie.

Complexity

n is the list length
ApproachTimeExtra space
Minimum of the whole listO(n)O(1)
Binary search, distinct valuesO(log n)O(1)
Binary search, repeats allowedO(log n) typical, O(n) worstO(1)
n is the list length. Scroll sideways on a small screen.

Edge cases

  • One element: the loop never runs.
  • No rotation: the comparison always pulls high left and ends at index 0.
  • Rotation by one, so the minimum is the last element.
  • Two elements, in either order.
  • Negative values, which change nothing but are worth one test.
  • For the repeated-value version: all values equal, and a single smaller value hidden among copies.

Slips to avoid

  • Setting high = mid - 1 when the middle is smaller, which can skip the minimum when the middle is the minimum.
  • Using while low <= high with high = mid, which loops forever once low equals high.
  • Comparing with the left end and failing on an unrotated list.
  • Returning the index when the question asked for the value, or the reverse. The rotation count is the index of the minimum, which some follow-ups ask for.
  • Claiming O(log n) for the repeated-value version without the worst-case caveat.

How to explain it out loud

Fictional example

Defending the right-end comparison
Candidate
The list is two increasing runs, and the minimum is the first value of the second run. I'll binary search for that point.
Candidate
If the middle is bigger than the last value, the drop has to be to the right of the middle, so I move low past it. Otherwise the middle through the end is sorted, so the minimum is the middle or earlier, and I set high to mid.
Interviewer
Why not compare against the first value?
Candidate
If the list isn't rotated at all, the middle is bigger than the first value but the minimum is at the start. The right end doesn't have that ambiguity, so the loop needs no special case.

Search in Rotated Sorted Array builds directly on this: either find the rotation point first, or decide at each step which half is in order. The boundary-style loop here is the same shape as the first-position variant in Binary Search and the speed search in Koko Eating Bananas. Find more on the coding problems hub.

Practicing with Natively

Interviewers often probe the choice of comparison here, so rehearse the 'why the right end' answer until it takes two sentences. Natively records a transcript of your practice session on Mac or Windows, which lets you see whether your explanation was clear or whether you circled. If you get stuck while practicing, it can read the problem from a screenshot and suggest which comparison to try. The AI assistant for coding interviews has more on how it works.

Questions people ask

How do you find the minimum in a rotated sorted array?

Binary search with low < high. If the middle value is greater than the value at high, set low to mid + 1; otherwise set high to mid. When the loop ends, low points at the minimum.

Why compare with the right end instead of the left?

A middle value smaller than the right end always means the middle is in the lower run. Comparing with the left end cannot tell an unrotated list from a rotated one without an extra check.

What changes if the array has duplicates?

When the middle equals the right end you cannot tell which side the minimum is on, so shrink high by one. It stays correct, but the worst case becomes O(n).

What is the time complexity?

O(log n) time and O(1) space for distinct values.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP