ExamAdda Logo

Find Minimum in Rotated Sorted Array

Easy

Given a sorted array of unique integers that has been rotated between 1 and n times, find the minimum element of the array.

The array was originally sorted in ascending order.

You must solve the problem in O(log n) time.

Example 1

Input

n = 5
nums = [3, 4, 5, 1, 2]

Output

1

Explanation

The original sorted array was:

[1, 2, 3, 4, 5]

 

After rotation, it became:

[3, 4, 5, 1, 2]

 

Therefore, the minimum element is 1.

Example 2

Input

n = 5
nums = [4, 5, 1, 2, 3]

Output

1

Explanation

The minimum element is 1.

Constraints

1 <= nums.length <= 5000
-5000 <= nums[i] <= 5000
All integers in nums are unique.
nums is sorted in ascending order before rotation.
The array is rotated between 1 and n times.

Hints:

Hint 1

Compare the middle element with the rightmost element.

Hint 2

If:

nums[mid] > nums[right]

 

the minimum must be in the right half.

Otherwise, the minimum is in the left half, including mid.

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Aug 22, 2026

Last updated

Aug 22, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output