Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find Minimum In Rotated Sorted Array

Medium Acceptance 89.00% Points 30.00

Given a rotated sorted array of distinct integers, return the minimum element in the array. The array was originally sorted in ascending order and then rotated at some unknown pivot. The task is to find the smallest element efficiently

Examples
Example 1

Example 1

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

Output: 1

Explanation: The original sorted array was [1,2,3,4,5], which was rotated. The smallest element is 1.

Example 2

Example 2

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

Output: 0

Explanation: The smallest element in the rotated array is 0.

Example 3

Example 3

Input: nums = [11,13,15,17]

Output: 11

Explanation: The array is already sorted and not rotated. The first element is the minimum.

Hints
Hint 1
N/A
Constraints
  • 1 = nums.length = 105
  • -104 = nums[i] = 104
  • All values in nums are distinct
Companies
Apple
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions