Chaturmind
LearnDSASystem DesignBlogPremium
Sign inGet started
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML

Company

  • Blog
  • Premium
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.

DSA›Binary Search›Find Minimum in Rotated Sorted Array
MediumBinary Search

Find Minimum in Rotated Sorted Array

binary-searcharray

Problem

Given a rotated sorted array of unique elements, find the minimum element in O(log n) time.

Examples

Example 1

Input: nums = [3,4,5,1,2]

Output: 1

Explanation: The array was rotated so 1 (the original minimum) sits at index 3.

Example 2

Input: nums = [4,5,6,7,0,1,2]

Output: 0

Explanation: 0 is the minimum.

Constraints

  • •1 <= nums.length <= 5000
  • •All values are unique

Hints

Hint 1

The minimum element is exactly the 'pivot point' where the rotation happened — everything before it is >= the first element, everything from it onward is < the first element.

Hint 2

Compare nums[mid] against nums[right], not nums[left] — it gives a cleaner signal for which side the minimum is on.

Hint 3

If nums[mid] > nums[right], the minimum must be to the right of mid (the rotation point hasn't been passed yet); otherwise it's at or before mid.

Solutions

public int findMin(int[] nums) {
    int left = 0, right = nums.length - 1;
    while (left < right) {
        int mid = (left + right) / 2;
        if (nums[mid] > nums[right]) {
            left = mid + 1; // minimum is to the right — mid is still on the 'high' side of the rotation
        } else {
            right = mid; // minimum is at mid or to its left — don't exclude mid itself
        }
    }
    return nums[left]; // left == right at the loop's end, pointing at the minimum
}
Java

Time: O(log n) · Space: O(1)