Minimum Number in a sorted rotated array
Easy Accuracy: 32.33% Submissions: 5150 Points: 2

A sorted array arr[] of size N which is rotated at some unknown point. The task is to find the minimum element in it. All the elements in the array are distinct.

Note: Expected time complexity is O(logN).

Input:
The first line of input contains an integer T denoting the number of test cases. Each test case contains the number of elements in the array arr[] as N and next line contains space separated n elements in the array arr[].

Output:
Print an integer which denotes the minimum element in the array.

Constraints:
1 <= T <= 100
1 <= N <= 107
1 <= arr[i] <= 107

Example:
Input:

2
10
2 3 4 5 6 7 8 9 10 1
5
3 4 5 1 2

Output:
1
1

Explanation:
Testcase 1:
The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1.

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.