Find Minimum in Rotated Sorted Array in Java: Explanation & Practice

Find the minimum element in rotated array

Problem summary

Given a rotated sorted array of unique elements, find the minimum element. The original array was sorted in ascending order.

Starter code

public class Main {
    public static void main(String[] args) {
        int[] nums = {3, 4, 5, 1, 2};
        
        // Minimum is at the rotation point
        // Binary search: if mid > right, min is in right half
        // Print: Min: 1
    }
}

Expected output and test cases

  • [3,4,5,1,2]
    Min: 1
  • [4,5,6,7,0,1,2]
    Min: 0
  • [1] → single element
    Min: 1

Hints

  1. If array not rotated (nums[left] < nums[right]), return nums[left]
  2. If nums[mid] > nums[right], minimum is in right half
  3. If nums[mid] <= nums[right], minimum is in left half (including mid)
  4. When left == right, we found the minimum

Related Data Structures & Algorithms exercises

Practice all Data Structures & Algorithms exercises · Run this idea in the Java compiler