Search in Rotated Sorted Array
Reported by candidates from Blinkit's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Blinkit reported this one in September 2026, and it's Search in Rotated Sorted Array dressed up with a function called searchRotatedArray. Strip the story and it's binary search with one extra question per step: which half is sorted? If you've got the OA in a day or two, that's the whole problem. The O(log n) requirement rules out a linear scan, so don't even start there. Know the sorted-half check cold and you're done in ten minutes. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment, but this one is learnable tonight.
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 every step of binary search, at least one half of the current range is sorted. Compare nums[lo] with nums[mid]. If nums[lo] <= nums[mid], the left half is sorted. Check if target falls inside it (nums[lo] <= target < nums[mid]). If yes, move hi to mid-1, otherwise move lo to mid+1. If the left isn't sorted, the right half is, so run the mirrored check. Values are distinct, so you skip the duplicate headache. The common pitfalls are using strict < instead of <= on the sorted check, which breaks two-element ranges, and getting the boundary inclusivity wrong on the target range. Also test the single-element array and an unrotated array. If you freeze on the boundary conditions during the live OA, StealthCoder is the hedge that hands you the clean version while you keep typing.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as search in rotated sorted array. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Blinkit's OA.
Blinkit reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Search in Rotated Sorted Array FAQ
How hard is Search in Rotated Sorted Array really?+
Medium difficulty, but it's a well-known one. The idea is simple and the bugs live in the boundary conditions. If you can write a standard binary search from memory, you're one extra if-statement away from this. Most failures come from off-by-one errors, not from missing the concept.
What's the trick for the Blinkit version?+
Decide which half is sorted by comparing nums[lo] to nums[mid]. Then check whether target sits inside that sorted half. If it does, search there. If not, search the other half. That single decision per step keeps you at O(log n) and handles every rotation.
Can I find the pivot first and then binary search?+
Yes. Find the smallest element with one binary search, then run a normal binary search on the correct side or with an index offset. It's two passes, still O(log n). The single-pass sorted-half method is shorter, so fewer places to slip up.
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 actually rotated, a target smaller than everything, and a target larger than everything. The example with nums = [1] and target 0 must return -1. Two-element cases catch most <= versus < mistakes.
How do I prepare for this in 48 hours?+
Write the solution from scratch three times without looking. Then dry-run it on [4,5,6,7,0,1,2] with targets 0 and 3. Spend leftover time on variants like the duplicates version so a twist doesn't throw you. Don't grind unrelated problems. This pattern is the whole question.