AlgoUniversity
  • Go Back
Discussion
Rotated Sorted Array :

Author

Akash

Difficulty Level : Easy

Submissions : 116

Asked In : Sigmoid

Marks :10

: 1 | : 0

Suppose an array of length $$$n$$$ sorted in ascending order is rotated between $$$1$$$ and $$$n$$$ times.

Notice that rotating an array $$$[a[0], a[1], a[2], ..., a[n-1]]$$$ $$$1$$$ time results in the array $$$[a[n-1], a[0], a[1], a[2], ..., a[n-2]].$$$

Given the sorted rotated array nums of unique elements, return this array's minimum and maximum elements.

You must write an algorithm that runs in $$$O(log$$$ $$$n)$$$ time.

Input

The first line contains the integer $$$n$$$ $$$(1 \le n \le 10^{5} )$$$, denoting the size of the input array.

The second line contains an array of N integers, $$$a_1,a_2...a_n$$$, $$$(-10^{9} \le a_i \le 10^{9} )$$$ in sorted rotated way.

Output

Return two integers, the minimum, and maximum element in the array.

Examples

Input
5
4 5 1 2 3
Output
1 5
Input
5
1 1 1 1 1
Output
1 1

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.