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

Lesson 5.5 of 10 in this module Unrolled Pro

Search in Rotated Sorted Array

Find a target in a sorted array that was rotated at an unknown point, in O(log n). From a linear scan, to two passes (find the rotation point, then search the right half), to one pass that uses the fact that one half around mid is always sorted. Then duplicates (where the worst case becomes O(n)), finding the rotation point alone, and searching a ring buffer of metrics whose write head has wrapped.

about 10 min 5 Python examples 2 quick checks

Problem. A sorted array of distinct integers was rotated at an unknown pivot: [0, 1, 2, 4, 5, 6, 7] might become [4, 5, 6, 7, 0, 1, 2]. Given the rotated nums and a target, return its index or −1, in O(log n).

text
nums = [4, 5, 6, 7, 0, 1, 2], target = 0   →   4
nums = [4, 5, 6, 7, 0, 1, 2], target = 3   →   -1
nums = [1],                   target = 0   →   -1

ML context. Rotated sorted data appears whenever a ring buffer wraps around: a fixed-size buffer of the last N metric samples, a replay buffer in reinforcement learning, a circular log on an edge device. Data is written in time order, but the oldest entry sits wherever the write head currently is. Finding "the sample at time t" means searching a rotated sorted array.


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 "Search 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