dsa · medium
Find Minimum in Rotated Sorted Array
nums is a distinct-valued array that was sorted ascending, then rotated at an unknown pivot. Return the **minimum** value. Logarithmic in n.
Arguments
nums— distinct values, originally sorted, then rotated
Example
[3,4,5,1,2] → 1.
[4,5,6,7,0,1,2] → 0.
[11,13,15,17] (no rotation) → 11.
Constraints
1 <= nums.length <= 5000 All values in nums are unique -10^4 <= nums[i] <= 10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [3,4,5,1,2] Expected: 1
Example 2
Input: [4,5,6,7,0,1,2] Expected: 0
Example 3
Input: [11,13,15,17] Expected: 11