Find Minimum in Sorted Rotated Array
Suppose an array of integers originally sorted in ascending order is rotated at some pivot unknown to you beforehand (i.e., [0, 1, 2, 4, 5, 6, 7] might become [4, 5, 6, 7, 0, 1, 2]). You must find and return the minimum element from the modified array. The modified array is guaranteed to contain at least one integer and no duplicates.
[ 4, 5, 6, 7, 0, 1, 2 ]
Explanation. The array was rotated at the index 3. The smallest value is the number 0.
[ 11, 13, 15, 17, -8, 2, 5 ]
Explanation. The array was rotated at the index 3. The smallest value is the number -8.
[ 2, 3, 4, 5, 6, 7, 8, 1 ]
Explanation. The array was rotated at the index 7. The smallest value is the number 1.
[ 5 ]
Explanation. The array contains only one element so there is no rotation at all. The smallest element is 5.
Follow-up: How will your solution change if duplicates are allowed in the array?
The array will not be empty and will contain at least one integer. All elements are unique. There is no limitation on the number of elements in the array.
- Views
- 4