Hints — p34 Find Minimum in Rotated Sorted Array

Read one at a time.


Hint 1 — The min is the rotation pivot. In a rotated sorted array, the min is the only index where nums[i-1] > nums[i] (or index 0 if unrotated). It’s where the “drop” happens.


Hint 2 — Anchor on nums[hi], not nums[lo]. Comparing nums[mid] to nums[hi] gives a single clean invariant. Comparing to nums[lo] forces extra cases for the unrotated array.


Hint 3 — The decision rule.

  • If nums[mid] > nums[hi], the pivot is STRICTLY right of midlo = mid + 1.
  • Else, the pivot is at mid or LEFT of midhi = mid (NOT mid - 1).

Hint 4 — Convergent loop.

while lo < hi:
    mid = (lo + hi) // 2
    ...
return nums[lo]

Use < (not <=). Loop ends with lo == hi == pivot index.


Hint 5 — Why hi = mid (not mid - 1)? Because nums[mid] itself might be the min. If we set hi = mid - 1, we lose the answer.


If still stuck: see solution.py. The loop is 5 lines.