Find Minimum in Rotated Sorted Array — Python Coding Problem
Difficulty: medium | Category: binary-search
Problem Description
Suppose a sorted array of unique elements has been **rotated** at some pivot. For example, `[0,1,2,4,5,6,7]` might become `[4,5,6,7,0,1,2]`. Given such an array `nums`, return the **minimum element**. You must write an algorithm that runs in **O(log n)** time. Hint: Binary search — if `nums[mid] > nums[right]`, the min is in the right half; otherwise it's in the left half (including `mid`).
Examples
Example 1
Input: nums = [3, 4, 5, 1, 2]
Output: 1
Example 2
Input: nums = [4, 5, 6, 7, 0, 1, 2]
Output: 0
Example 3
Input: nums = [11, 13, 15, 17]
Output: 11
Explanation: Not rotated — minimum is first element.