Practice

Find Minimum in Rotated Sorted Array

Module 13 · Binary Search

Problem

A sorted array (distinct values) has been rotated at an unknown pivot. Return the minimum element, in O(log n).

Examples

Example 1

Inputnums = [3,4,5,1,2]Output1

Example 2

Inputnums = [4,5,6,7,0,1,2]Output0

Example 3

Inputnums = [11,13,15,17]Output11

Explanation. not rotated at all — pivot = 0

Constraints

1 ≤ n ≤ 5000 · distinct values.

Attempt it first

The module's capstone: it's the boundary-search template (lesson 2) applied to Search in Rotated Sorted Array's "one sorted half" insight (the previous problem). Define the right monotonic predicate over positions and this becomes a single clean binary search — no target to compare against, just structure.