Reported September 2026
Amazonbinary search

Search in a Rotated Sorted Array

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

The O(log n) requirement in this Amazon OA question is the whole point. Reported in September 2026, it hands you a sorted array that got rotated at an unknown pivot, all values distinct, and asks for the index of a target or -1. A linear scan passes the examples and fails the requirement. This is binary search with one twist, and you've likely seen it. If you blank on the twist during the assessment, StealthCoder is the invisible safety net that reads the problem and gives you the solution live. Better to know the trick before you open the timer.

The problem

Given an integer array nums that was sorted in strictly increasing order and then rotated at an unknown pivot, and an integer target, return the index of target.
Return -1 when target does not appear in nums.
All values in nums are distinct. Your solution must run in O(log n) time.

Function
searchRotatedArray(nums: int[], target: int) → int

Examples
Example 1
nums = [4,5,6,7,0,1,2]
target = 0
return = 4
The target 0 appears at index 4.
Example 2
nums = [4,5,6,7,0,1,2]
target = 3
return = -1
The target 3 is absent, so the result is -1.
Example 3
nums = [1]
target = 0
return = -1
The only array value is 1, so 0 is absent.

Constraints
1 <= nums.length <= 10^5
-10^9 <= nums[i] <= 10^9
nums contains distinct values.
nums was sorted in strictly increasing order and rotated at an unknown pivot.
-10^9 <= target <= 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: at any mid, at least one half of the array is properly sorted. Compare nums[lo] to nums[mid]. If nums[lo] <= nums[mid], the left half is sorted. Check whether target falls inside [nums[lo], nums[mid]). If yes, move hi to mid - 1, otherwise move lo to mid + 1. If the left half isn't sorted, the right half is, so run the mirrored check. The common pitfall is the boundary comparison. Use <= on nums[lo] <= nums[mid] because lo and mid can be the same index when two elements remain. Another miss is forgetting the target equals nums[mid] check first. Distinct values mean no duplicate-handling mess. Test [1] with target 0 and a two-element rotation like [3,1]. If the logic tangles mid-assessment, StealthCoder can hand you the clean version as a hedge.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Search in a Rotated Sorted Array cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as search in rotated sorted array. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Search in a Rotated Sorted Array FAQ

How hard is Search in a Rotated Sorted Array really?+

Medium. The idea is simple once you see that one half is always sorted. Most failures come from off-by-one errors on the boundary checks, not from the concept. If you can write plain binary search cleanly, you're one idea away.

What's the trick for the Amazon version reported in September 2026?+

At each mid, figure out which half is sorted by comparing nums[lo] to nums[mid]. Then check if the target lies in that sorted half's range. Keep that half or discard it. That keeps every step O(log n) with no pivot search needed.

Do I need to find the pivot first?+

No. You can find the pivot with one binary search and then search again, which works. But the single-pass version is shorter and has fewer edge cases. Either is O(log n), so pick the one you can write without bugs.

Which edge cases should I test before submitting?+

Test a single-element array, a two-element rotated array like [3,1], an array that isn't rotated at all, a target smaller than everything, and a target larger than everything. Also check the target at index 0 and at the last index.

How do I prepare for this in 48 hours?+

Write the single-pass solution from memory three times, then dry-run it on [4,5,6,7,0,1,2] with targets 0 and 3. Get the <= in the sorted-half check burned in. Then spend remaining time on related binary search variants.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it