#153MediumBinary Search

Find Minimum in Rotated Sorted Array

Binary search on the inflection point of a rotated sorted array.

AmazonMicrosoftBloombergUber

Problem Statement

Suppose an array of length n sorted in ascending order is rotated between 1 and n times. Given the array nums after rotation, return the minimum element. You must write an algorithm that runs in O(log n) time.

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

Constraints

  • n == nums.length
  • 1 ≤ n ≤ 5000
  • −5000 ≤ nums[i] ≤ 5000
  • All integers in nums are unique.

Solutions

1
Linear Scan
TimeO(n)SpaceO(1)

Scan the array and return the minimum. O(n). Doesn't use the sorted property.

Visual Animation
def findMin(nums: list[int]) -> int:
    return min(nums)

Related Concepts

Deepen your understanding with these related topics from our AI Glossary:

Deepen your understanding

Want to master the core concepts?

Our free AI Glossary covers 190+ topics — from Binary Search to Dynamic Programming, Machine Learning, SQL, and more. Structured learning tracks for every level.

Browse AI Glossary All Problems
39+
AI Models
₹69
Per day used
4
Languages

Stuck? Ask AI to explain it step by step.

Ask Claude, GPT-4o, or Gemini to debug your code, generate test cases, or walk through the intuition. 39+ models. Pay only on days you use it — no subscription required.

Free to start · No credit card required to explore

Get Started Free
Back to all problems