InterviewLegend

Search in Rotated Sorted Array

Alex Chen25 min readMedium

Regular binary search falls apart the moment the array stops being fully sorted, and a rotated array looks exactly like that broken case. It isn't. Rotate a sorted array at some pivot and you get two sorted runs stitched together, so whichever midpoint you pick, one side is always a clean sorted stretch. Find that side, ask whether the target sits inside its range, and throw the other half away, all for the same O(log n) with one extra branch.

What's inside
  • 1 problem, worked step by step
  • 3 diagrams
  • about 25 min

Premium lessonData Structures & Algorithms

Keep going with Premium.

All 78 lessons and 103 worked problems in this course, plus what 100 companies ask, pulled from 20,000+ candidate reports.

100 companies. Checked every month.

Unlock the full course

$49 a year · less than $1 a week · Cancel anytime