PROBLEM 16 OF 75

Search in Rotated Sorted Array

Find a target index in a rotated sorted array with distinct values.

PATTERNBinary searchDefine which half is impossible before moving a bound.
SPOT THE SIGNAL

Why does this pattern fit?

FRAME · 1 OF 4

Restate the exact job

Find a target index in a rotated sorted array with distinct values.

WHY THIS FITS

At least one half around mid is normally sorted.

COMPLEXITY

O(log n) time · O(1) space

COMMON FAILURE

Comparing only target with mid ignores the rotation.

THE REASONING, IN ONE PLACE

How to solve Search in Rotated Sorted Array

The goal is to solve this problem from the pattern, not to memorize a finished answer. Use this as a check after your own attempt.

What the question asks

Find a target index in a rotated sorted array with distinct values.

Why Binary search fits

At least one half around mid is normally sorted.

State to maintain

An inclusive candidate interval.

Transition

Identify the sorted half; keep it only if the target lies within its bounds.

Time and space

O(log n) time · O(1) space

Counterexample to the tempting mistake

Comparing only target with mid ignores the rotation.

Prove it again tomorrow

Close this page. Rebuild the state and transition from memory, write a test that exposes the mistake above, then solve a fresh input without looking back. A same-day reread is practice, not proof of retention.

Open blank recall ↗