Imagine an array that was originally sorted in ascending order and then rotated to the left some unknown number of times, so a slice of the front got moved to the back. Every element is unique. Your job is to return the smallest value that remains hidden somewhere inside this rotated arrangement.
A sweep across all elements would obviously work, but the array's structure lets you discard half of the remaining candidates at each step, so an efficient solution should run in logarithmic time.
Example 1
Input: nums = [3,4,5,1,2]
Output: 1
The original [1,2,3,4,5] was rotated so the minimum 1 landed in the middle.
Example 2
Input: nums = [4,5,6,7,0,1,2]
Output: 0
After rotation the smallest value 0 sits at index 4.
Constraints
n == nums.length1 ≤ n ≤ 5000-5000 ≤ nums[i] ≤ 5000All integers in nums are uniqueSee the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI