Skip to main content

13. Find Minimum in Rotated Sorted Array

mediumAsked at Brex

Locate the minimum element in a rotated sorted array in O(log n) — tests binary search intuition commonly seen in Brex's infrastructure and data pipeline rounds.

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Problem

Suppose an array of length n sorted in ascending order is rotated between 1 and n times. Given the rotated array nums with all unique values, return the minimum element in O(log n) time.

Constraints

  • n == nums.length
  • 1 <= n <= 5000
  • -5000 <= nums[i] <= 5000
  • All integers are unique

Examples

Example 1

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

Example 2

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

Approaches

1. Linear scan

Iterate through the array and track the minimum value seen.

Time
O(n)
Space
O(1)
let min = nums[0];
for (const n of nums) min = Math.min(min, n);
return min;

Tradeoff:

2. Binary search on rotation pivot

Use binary search: if mid element is greater than right, the minimum is in the right half. Otherwise it is in the left half including mid. Converge to the pivot.

Time
O(log n)
Space
O(1)
function findMin(nums) {
  let lo = 0, hi = nums.length - 1;
  while (lo < hi) {
    const mid = (lo + hi) >> 1;
    if (nums[mid] > nums[hi]) {
      lo = mid + 1;
    } else {
      hi = mid;
    }
  }
  return nums[lo];
}

Tradeoff:

Brex-specific tips

Brex asks about fintech infrastructure, multi-currency handling, and spend management algorithms. Expect LeetCode-style DSA focused on hash maps, sorting, and dynamic programming.

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

Practice these live with InterviewChamp.AI

Drill Find Minimum in Rotated Sorted Array and other Brex interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →