InferenceAI

Enter at least two characters to search.

Start free

Rotated List Minimum

mediumBinary Search25 min25 XP

A list of distinct integers was sorted in ascending order and then rotated at an unknown pivot (for example [0, 1, 2, 4, 5] became [4, 5, 0, 1, 2]). Return its minimum.

Requirements

  • O(log⁡n)O(\log n) time.

Constraints

  • 1≤n≤50001 \le n \le 5000; all values are distinct.

Examples

EXAMPLE WALKTHROUGHrotated

A guided view of the published example, not a trace of your code.

INPUT[[3,4,5,1,2]]
TASKrotated_list_minimum()
EXPECTED OUTPUT1

Start with the input values shown in this example.

Example 1 of 3

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

Output: 1

Explanation: rotated

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

Output: 0

Explanation: longer

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

Output: 11

Explanation: not rotated

Hint 1

Compare the middle value with the last value.

Hint 2

If nums[mid] > nums[hi], the minimum is to the right of mid; otherwise it is at mid or to its left.

Topics

DSABinary SearchPython