Reported October 2025
Motivebinary search

Search in Rotated Sorted Array

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

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

Motive reportedly put Search in Rotated Sorted Array in front of candidates in October 2025. Strip the rotation story and it's one question: at every step, which half of the array is still sorted? That's binary search with one extra check. If you've seen it, you can write it in ten minutes. If you haven't, the pivot logic can eat your brain under a timer. StealthCoder sits invisibly on your screen during the live OA as a safety net if you blank on the boundary conditions. Everything you need is below.

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: pick mid, then at least one side of it is always 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, set hi = mid - 1, otherwise lo = mid + 1. If the left half isn't sorted, the right half is, so run the mirror check. The common pitfall is the comparison operators. Use <= on nums[lo] <= nums[mid] because lo and mid can be the same index with a one or two element window. Another trap is looking for the pivot first and doing two searches. It works, but it's more code and more bugs. Values are distinct, so no duplicate handling is needed. Target must be O(log n), so a linear scan fails the requirement. If the boundary checks slip away mid-assessment, StealthCoder is the hedge that gives you a working solution on the spot.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Search in 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

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 Motive's OA.

Motive reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Search in Rotated Sorted Array FAQ

What's the trick to Search in Rotated Sorted Array?+

At each step, one half around mid is sorted. Find which one by comparing nums[lo] with nums[mid]. Then check whether target lies inside that sorted half. If it does, search there. If not, search the other half. It's one binary search loop with a branch.

How hard is this problem really?+

Medium, but it's a well-known one. The idea is simple once you see it. The difficulty is off-by-one errors in the range checks. Write the loop on paper with [4,5,6,7,0,1,2] and target 0 once, and the conditions will click.

Do I need to find the pivot first?+

No. You can find the pivot and then binary search the right segment, but it's two passes and more edge cases. The single-pass approach compares against the sorted half at each step and is shorter and easier to get right.

What edge cases should I test before submitting?+

Test a single element array like [1] with target 0, which should return -1. Test an array that isn't visibly rotated, a target at the first or last index, and a target that's absent like 3 in [4,5,6,7,0,1,2]. Two-element arrays catch the <= mistake.

How do I prepare for this in 48 hours?+

Code the one-pass solution from scratch three times without looking. Then do a plain binary search and one variant like finding the minimum in a rotated array. Focus on the loop condition lo <= hi and the sorted-half check. That covers what Motive reportedly asked in October 2025.

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

OA at Motive?
Invisible during screen share
Get it