|
| 1 | +# Find Minimum in Rotated Sorted Array |
| 2 | + |
| 3 | +**Difficulty:** Medium |
| 4 | +**Topics:** Array, Binary Search |
| 5 | +**Tags:** blind-75 |
| 6 | + |
| 7 | +**LeetCode:** [Problem 153](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/) |
| 8 | + |
| 9 | +## Problem Description |
| 10 | + |
| 11 | +Suppose an array of length `n` sorted in ascending order is **rotated** between `1` and `n` times. For example, the array `nums = [0,1,2,4,5,6,7]` might become: |
| 12 | + |
| 13 | +- `[4,5,6,7,0,1,2]` if it was rotated `4` times. |
| 14 | +- `[0,1,2,4,5,6,7]` if it was rotated `7` times. |
| 15 | + |
| 16 | +Notice that **rotating** an array `[a[0], a[1], a[2], ..., a[n-1]]` 1 time results in the array `[a[n-1], a[0], a[1], a[2], ..., a[n-2]]`. |
| 17 | + |
| 18 | +Given the sorted rotated array `nums` of **unique** elements, return _the minimum element of this array_. |
| 19 | + |
| 20 | +You must write an algorithm that runs in O(log n) time. |
| 21 | + |
| 22 | +## Examples |
| 23 | + |
| 24 | +### Example 1: |
| 25 | + |
| 26 | +``` |
| 27 | +Input: nums = [3,4,5,1,2] |
| 28 | +Output: 1 |
| 29 | +Explanation: The original array was [1,2,3,4,5] rotated 3 times. |
| 30 | +``` |
| 31 | + |
| 32 | +### Example 2: |
| 33 | + |
| 34 | +``` |
| 35 | +Input: nums = [4,5,6,7,0,1,2] |
| 36 | +Output: 0 |
| 37 | +Explanation: The original array was [0,1,2,4,5,6,7] and it was rotated 4 times. |
| 38 | +``` |
| 39 | + |
| 40 | +### Example 3: |
| 41 | + |
| 42 | +``` |
| 43 | +Input: nums = [11,13,15,17] |
| 44 | +Output: 11 |
| 45 | +Explanation: The original array was [11,13,15,17] and it was rotated 4 times. |
| 46 | +``` |
| 47 | + |
| 48 | +## Constraints |
| 49 | + |
| 50 | +- n == nums.length |
| 51 | +- 1 <= n <= 5000 |
| 52 | +- -5000 <= nums[i] <= 5000 |
| 53 | +- All the integers of nums are **unique**. |
| 54 | +- nums is sorted and rotated between 1 and n times. |
0 commit comments