Leaderboard
Showing:
Minimum element in a sorted and rotated array
Easy Accuracy: 64.98% Submissions: 6742 Points: 2

A sorted array A[ ] with distinct elements is rotated at some unknown point, the task is to find the minimum element in it.

Example

Input
N = 5
arr[] = {4 ,5 ,1 ,2 ,3}
Output
1
Explanation: 1 is the minimum element in
the array.

Example

Input
N = 6
arr[] = {10, 20, 30, 40, 50, 5, 7}
Output
5
Explanation:
Here 5 is the minimum element.

 

Your Task:
Complete the function findMin() which takes an array arr[] and n, size of the array as input parameters, and returns the minimum element of the array.

Expected Time Complexity: O(log N).
Expected Auxiliary Space: O(log N).

Constraints:
1 ≤ N ≤ 100000
1 ≤ A[i] ≤ 1000000

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.

Minimum element in a sorted and rotated array

Output Window