ASAPUtils Logo ASAPUtils
Week 4

Search in Rotated Sorted Array

Search a rotated sorted array in O(log n) by identifying the ordered half, with the interval invariant, C++ and JavaScript implementations, boundary reasoning, common comparison bugs, and an interactive trace.

medium Arrays Binary Search O(log n) time · O(1) space Open on LeetCode ↗

The problem

A strictly ascending array of unique integers may have been rotated at an unknown pivot. Return the index of a target in logarithmic time, or minus one if it is absent.

nums = [4,5,6,7,0,1,2], target = 0 -> 4

Related Problems