Minimum in Rotated Sorted Array
Let's try our approach when the input is a rotated and sorted array. Difficulty Level: Medium
We'll cover the following...
We'll cover the following...
Problem statement
Suppose an array that was sorted in ascending order is rotated. For example, the array nums = [0,1,2,4,5,6,7] might become:
[4,5,6,7,0,1,2], if it is rotated4times.[0,1,2,4,5,6,7], if it is rotated7times.
Notice the rotation of an array [nums[0], nums[1], nums[2], ..., nums[n-1]] 1 time results in the array [nums[n-1], nums[0], nums[1], nums[2], ..., nums[n-2]].
Given sorted and rotated array nums, return the minimum element in the array.
Constraints:
- All of the integers of
numsare unique. numsis sorted and rotated.
Example 1:
Input: [3,4,5,1,2]
Output: 1
Explanation: The original array was [1,2,3,4,5], and it was rotated 3 times.
Example 2:
Input: [4,5,6,7,0,1,2]
Output: 0
Explanation: The original array was [0,1,2,4,5,6,7], and it was ...