The Search in Rotated Sorted Array interview question gives you a sorted array that has been rotated at some unknown pivot point (e.g., [4,5,6,7,0,1,2] is [0,1,2,4,5,6,7] rotated at index 4). Given a target, find its index in O(log n) time. All values are distinct.
This is asked at virtually every major company — Apple, Uber, Goldman Sachs, Microsoft, Meta, Amazon, Google, Bloomberg, Adobe, and many more — because it extends binary search to a non-standard sorted structure. It is a classic example of "modified binary search" where the sorted property is partially broken and candidates must identify which half is still sorted before deciding which direction to search.
The pattern is modified binary search with half-sorted-half identification. At each step, compute mid. Identify which half is sorted: if nums[left] <= nums[mid], the left half is sorted. Check if target falls in the sorted range [nums[left], nums[mid]). If yes, narrow to left half; otherwise search right. If the right half is sorted (nums[mid] <= nums[right]), apply the same logic for [nums[mid], nums[right]].
Array: [6, 7, 0, 1, 2, 4, 5], target = 0.
nums[left] < nums[mid] (strict) instead of <=, causing incorrect behavior when left == mid.<= vs < boundaries feel natural.For the Search in Rotated Sorted Array coding problem, the binary search array interview pattern with rotation handling is the key. The single insight to memorize: at each step, one half is always sorted. Use this to decide which half contains the target. Interviewers at Grammarly and Anduril test edge cases: what if target is at the pivot? What if the array has 1 or 2 elements? Practice these explicitly.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find Peak Element | Medium | Solve | |
| Find Minimum in Rotated Sorted Array | Medium | Solve | |
| Koko Eating Bananas | Medium | Solve | |
| Find First and Last Position of Element in Sorted Array | Medium | Solve | |
| Capacity To Ship Packages Within D Days | Medium | Solve |