FAANG · LeetCode #33
Search in Rotated Sorted Array — three-stage drill
1The ProblemMedium
Search in Rotated Sorted Array
Find a target's index in a sorted array that's been rotated.
Examples
[5,6,7,0,1,2,4], t=4→ 6t=8→ -1
constraintDistinct values; the array is a sorted array rotated at one pivot.
2The PatternTIME O(log n) · SPACE O(1)
Binary Search
Halve the search space each step — check the middle, keep the half that can hold the answer.
Problems using this pattern
3The SolutionRESULT → 6
Step through it
rotated sorted array · target = 4 · left = 0, right = 6
Step 1 / 4
Arrow keys to navigate · escape to reset