You have a
sorted and rotated
array
arr[]
of size
n
where elements are sorted and rotated circularly. Write a program to find the minimum element in the array.
Problem Note
-
Suppose the elements in the array
arr[]
are [1, 2, 3, 4, 5, 6, 7], then rotating by three times array becomes [4, 5, 6, 7, 1, 2, 3]. - You won’t be provided with the number of times array is rotated.
- The array will not contain duplicates.
- Also, think about the case when there are duplicates. Does your current solution work?
Example 1
Input: arr[] = [4, 5, 6, 7, 1, 2, 3]
Output: 1
Explanation: The minimum element in arr[] is 1.
Example 2
Input: arr[] = [8, 9, 4, 5, 6, 7 ]
Output: 4
Explanation: The smallest element is 4 in the array arr[].
Example 3
Input: arr[] = [3, 4, 5, 6, 7]
Output: 3
Explanation: The minimum element is 3 in the array arr[].
Example 4
Input: arr[] = [3, 2]
Output: 2
Explanation: The minimum element is 2 in the array arr[].