Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Find Minimum in Rotated Sorted Array

Searchingmedium

Given a rotated sorted array `nums` of distinct values, implement `findMin(nums)` returning the minimum element.

Sample tests

Input: findMin([3,4,5,1,2])
Output: 1
Input: findMin([4,5,6,7,0,1,2])
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Comparing to the left end instead, which fails for some rotations.

Learning resources

  • Wikipedia: Binary search
Approach & explanation (try first)

Binary search comparing mid to the right end finds the rotation minimum in O(log n).

Loading...
⌘/Ctrl + Enter

Run your code to see results.