Minimum Number in a sorted rotated array
Submissions: 3066   Accuracy:

38.19%

  Difficulty: Easy   Marks: 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.

 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Shashwat Jain
Author: shashwat jain


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.