15% off all plans & roadmaps Use code
See plansLeetCode 81 · Solution & editorial
There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values).
Search in Rotated Sorted Array II 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 II has been reported in interviews at Amazon.
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 II 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.