VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 05: Binary search

Lesson 5.6 of 10 in this module Unrolled Pro

Find Minimum in Rotated Sorted Array

Find the smallest value of a sorted array rotated at an unknown point, in O(log n). From min() over everything, to a boundary search against the first element (with a special case when nothing was rotated), to comparing mid with the right end, which needs no special case. Then duplicates (O(n) worst case), the rotation count, the largest value, and finding the oldest entry of a ring buffer whose write head is unknown.

about 10 min 5 Python examples 2 quick checks

Problem. A sorted array of distinct integers was rotated between 1 and n times: [0, 1, 2, 4, 5, 6, 7] may become [4, 5, 6, 7, 0, 1, 2], or stay as it was after n rotations. Return the minimum, in O(log n).

text
[3, 4, 5, 1, 2]          →   1
[4, 5, 6, 7, 0, 1, 2]    →   0
[11, 13, 15, 17]         →   11      (rotated n times: sorted again)

ML context. The minimum of a rotated sorted array is the oldest entry of a ring buffer. A metrics agent or a replay buffer writes samples in time order into a fixed array and wraps around. After a restart, the write head is often lost, but the timestamps are still there: finding the oldest one tells you where the buffer starts, and then every other lookup is an ordinary binary search (lesson 5.5, Change C).


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Find Minimum in Rotated Sorted Array"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee