15% off all plans & roadmaps Use code
See plansLeetCode 33 · Solution & editorial
There is an integer array nums sorted in ascending order (with distinct values).
Search in Rotated Sorted Array is a Binary Search Patterns problem, in the Find Min/Max in Rotated Sorted Array subpattern. The pattern covers standard binary search, rotated arrays, first/last occurrence, and search on answer space
Master binary search in rotated sorted arrays. Find minimum, search elements, and handle duplicates.
The reference solution runs in O(logn) time and O(1) space.
Search in Rotated Sorted Array has been reported in interviews at Amazon, Facebook, Microsoft, LinkedIn, Oracle, Apple, Bloomberg, Nvidia.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Search in Rotated Sorted Array is a Binary Search Patterns problem, in the Find Min/Max in Rotated Sorted Array subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.