The problem. A sorted array of distinct values has been rotated: some number of values were moved from the front to the back, so [0, 1, 2, 4, 5, 6, 7] might become [4, 5, 6, 7, 0, 1, 2]. Given the rotated array, return its minimum value in O(log n) time.
nums = [3, 4, 5, 1, 2] -> 1
nums = [4, 5, 6, 7, 0, 1, 2] -> 0
nums = [11, 13, 15, 17] -> 11 (rotated all the way round: sorted again)Members only · free account
The rest of this lesson, with 7 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson