LeetCode 153 · Medium

Find Minimum in Rotated Sorted Array Explained (LeetCode 153)

Updated Nov 27, 2026 · 3 min read

Use binary search and compare the middle value with the last value in the range. If the middle is bigger, the drop (and the minimum) is to the right, so move left to mid + 1. Otherwise the minimum is at mid or to its left, so move right to mid. When left meets right, that index holds the minimum, in O(log n) time and O(1) space.

Watch onYouTubeInstagram

Key points

  • ●A rotated sorted array is two sorted runs; the minimum sits where the high run drops to the low run.
  • ●Compare nums[mid] with nums[right], not nums[left].
  • ●Middle bigger: left = mid + 1. Otherwise: right = mid, because mid might be the answer.
  • ●Each comparison halves the range: about 20 peeks for a million numbers, O(log n).
Step-by-step visual sheet: Find Minimum in Rotated Sorted Array
The full visual sheet, made with Edithly.Open the interactive sheet

The riddle: someone cut Nia's shelf

Nia's books were lined up from smallest to biggest. Then someone took a chunk off the front and moved it to the back, without changing its order. Now the shelf reads 15, 18, 22, 3, 7, 11. Which book is the smallest?

That's LeetCode 153, Find Minimum in Rotated Sorted Array. You get a list of different numbers that was sorted and then rotated, and you return the smallest. The catch is the time limit: the solution has to run in O(log n), so you can't just look at every number.

The slow way: check every book

Scanning the whole shelf and keeping the smallest works. Six books, six looks. A million books, a million looks. That's O(n), and the problem asks for better.

The idea: two sorted runs and one drop

Rotation doesn't scramble the list. It leaves two sorted runs side by side: a high run (15, 18, 22) followed by a low run (3, 7, 11). The smallest number sits exactly where the high run drops into the low run. So the job is to find the drop.

Nia peeks at two books: the one in the middle of her current range and the one at the right end.

  • Middle bigger than the right end? The middle is in the high run, so the drop is somewhere to its right. Move left to mid + 1.
  • Otherwise? The middle is in the low run. The smallest is the middle itself or something to its left. Move right to mid.

Each peek cuts the range in half, and the minimum always stays inside it. That's the invariant on the sheet: the answer is always somewhere between left and right, so you only throw away a half once a comparison proves the minimum can't be there.

Trace it on Nia's shelf

Range [left, right] mid Compare New range
[0, 5] 2 22 > 11 [3, 5]
[3, 5] 4 7 < 11 [3, 4]
[3, 4] 3 3 < 7 [3, 3]

Left and right meet at index 3, and nums[3] is 3. Three peeks. Step 4 of the visual sheet above shows the range shrinking from six candidates to three, then two, then one.

The code in Python

def find_min(nums):
    left, right = 0, len(nums) - 1
    while left < right:
        mid = (left + right) // 2
        if nums[mid] > nums[right]:
            left = mid + 1
        else:
            right = mid
    return nums[left]

The loop runs while there's more than one candidate. When left == right, there's nothing left to compare, and that index is the answer.

Complexity

  • Time: O(log n). Each comparison halves the range, so a million numbers takes about 20 peeks.
  • Space: O(1), just two pointers and a middle index.

From O(n) to O(log n) by asking one question per step.

The trap to watch for

Two small changes break this solution.

Writing right = mid - 1. In the else branch, the middle value might be the minimum. In the trace above, the last step compares 3 with 7, and 3 is the answer. Skipping past mid would lose it.

Comparing with the left end. nums[left] doesn't tell you which run the middle is in as cleanly, because a fully sorted (unrotated) range and a rotated one can look the same from the left. The right end always settles it, which is why the whole solution hangs on nums[mid] > nums[right].

Frequently asked questions

Why compare the middle with the right end instead of the left?

The right end tells you which sorted run the middle is in. If nums[mid] is bigger than nums[right], mid is in the high run and the drop is strictly to its right. If not, mid is in the low run, so the minimum is mid itself or something to its left.

Why is it right = mid and not right = mid - 1?

Because in the else branch the middle value could be the minimum. Setting right = mid - 1 could throw the answer away. Only the other branch, where nums[mid] > nums[right], proves mid is not the minimum.

What is the time complexity of Find Minimum in Rotated Sorted Array?

O(log n) time, since every comparison halves the candidate range, and O(1) extra space for the two pointers.

What if the array is not rotated at all?

It still works. In a fully sorted array nums[mid] is never bigger than nums[right], so right keeps moving toward index 0, and the loop returns the first element.

Turn any problem or document into a visual sheet like this one

Paste a LeetCode problem, a PDF or a link into Edithly and get a step-by-step sheet you can study, share or quiz yourself on.

Make this sheet in Edithly, free