Find Minimum in Rotated Sorted Array

MediumBinary Search
Next
Binary SearchArray

A sorted array of distinct integers was rotated at an unknown pivot. Find the minimum element in O(log n).

Input

Line 1: n. Line 2: the rotated array.

Output

Print the minimum value.

Constraints

1 <= n <= 10^5 All values are distinct.

Example 1
Input
5
3 4 5 1 2
Output
1

The array was rotated and 1 is the smallest.

Example 2
Input
4
11 13 15 17
Output
11

Not rotated (or rotated fully): the first element is the minimum.

Hints

Find Minimum in Rotated Sorted Array - Medium Binary Search Problem | Skill Shiksha