2.Find Minimum in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. Find the minimum element. You may assume no duplicate exists in the array.
Solution:
This is an optimized solution using binary search O(log n) time. Another implementation can be using linear search which requires O(n) time.
Type II:
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. Find the minimum element. The array may contain duplicates.
Solution:
Using duplicates with the above solution will take O(n) time.
The below solution takes O(log n) time.
Last updated