Skip to content

visual walkthrough

Find Minimum in Rotated Sorted Array

MediumRotated Sorted ArrayReported at: AmazonMetaMicrosoft+4

Compare with the right end to find the pivot.

Solve on LeetCode

The idea

A turned sorted array is two sorted runs. Everything in the first run is bigger than everything in the second, and the minimum starts the second run.

Comparing arr[mid] with arr[hi] tells you which run mid is in, so you can drop half.

Complexity

approachtimespace
Scan for the smallestO(n)O(1)
Binary search for the dropO(log n)O(1)

More walkthroughs