You have a sorted and rotated array where elements are sorted and rotated circularly. Write a program to find the minimum element in the array.

Problem Note

  • Suppose the elements in array are [1, 2, 3, 4, 5, 6, 7], then rotating by three time array becomes [4, 5, 6, 7, 1, 2, 3].
  • You won’t be provided with number 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: A[] = [4, 5, 6, 7, 1, 2, 3]
Output: 1

Example 2

Input: A[] = [8, 9, 4, 5, 6, 7 ]
Output: 4

Example 3

Input: A[] = [3, 4, 5, 6, 7]
Output: 3

Example 4

Input: A[] = [3, 2]
Output: 2