Practice · Binary search · 5 of 5

Smallest Value in a Rotated Sorted List

A list of different integers was sorted in increasing order and then rotated: some of its items were moved, in order, from the end to the front. For example, [1, 2, 4, 6, 7] rotated by two becomes [6, 7, 1, 2, 4]. It may have been rotated by any amount, including none.

Given the rotated list nums, return its smallest number in O(log n) time.

Example 1

Input
nums = [6, 7, 1, 2, 4]
Output
1

Example 2

Input
nums = [11, 13, 15, 17]
Output
11
This list wasn't rotated at all, so the minimum is at the front.

Constraints

  • nums holds 1 to 5000 numbers, all different.
  • Every number is between −5000 and 5000.
  • nums is an increasing list rotated by some amount from 0 to n − 1.