Facebook PixelFind Minimum in Rotated Sorted Array — Coding Practice
Find Minimum in Rotated Sorted ArrayMedium

Find Minimum in Rotated Sorted Array

Medium 14.2k49% acceptance
ArrayBinary Search

An ascending array of distinct integers was rotated between 1 and n times (a rotation moves the last element to the front). Given the resulting array nums, return its minimum element.

Your algorithm must run in O(log n) time.

Example 1
Input: nums = [3,4,5,1,2]
Output: 1
The original [1,2,3,4,5] was rotated 3 times; the smallest value is 1.
Example 2
Input: nums = [11,13,15,17]
Output: 11
A full (or zero) rotation leaves it sorted — the minimum is simply the first element.
Constraints
  • 1 ≤ nums.length ≤ 5000
  • -5000 ≤ nums[i] ≤ 5000
  • All integers are distinct.
Asked atAmazonMicrosoftGoogleBloomberg
JavaScript
Loading editor…
Case 1
[3,4,5,1,2]
expected: 1
Case 2
[4,5,6,7,0,1,2]
expected: 0
Case 3
[11,13,15,17]
expected: 11
Case 4
[2,1]
expected: 1
Case 5
[1]
expected: 1
Case 6
[5,1,2,3,4]
expected: 1