Find Minimum in Rotated Sorted Array

Medium#153rotated array

A sorted array of distinct numbers was rotated: some numbers from its start moved to its end, keeping their order. Find the smallest number in O(log n) time. Our example: [15, 18, 22, 3, 6, 9, 11] — the answer is 3.

input
nums: different integers in ascending order, rotated: moved round by some places, so [1, 3, 5, 7] may come as [5, 7, 1, 3] or as it was.
returns
The smallest number of nums. LeetCode wants it in O(log n).
constraints
  • 1 ≤ nums.length ≤ 5000
  • −5000 ≤ nums[i] ≤ 5000
  • nums is an ascending array of different numbers, rotated
our 12 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.
/**
 * @param {number[]} nums
 * @return {number}
 */
function findMin(nums) {

}
Ctrl ↵
format
reset

saved in this browser

12 tests · limit 3 s

Stuck?

See the solution run step by step on our example, then why it works and its complexity.

Watch the walkthrough →

Next: more binary search problems

Pattern “Binary search” →

The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.