Reported September 2026
Capgeminibinary search

Search in Rotated Sorted Array

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

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

The Capgemini OA reported in September 2026 has one line that decides everything: the solution must run in O(log n). That rules out a linear scan, even though it would pass the examples. This is Search in Rotated Sorted Array, a binary search problem with a twist. The array was sorted, then rotated at an unknown pivot, and all values are distinct. If you've seen it before, it's a ten-minute problem. If you blank on the boundary conditions, it gets ugly fast. StealthCoder sits invisibly on your screen during the live assessment as a safety net, so a blank doesn't sink the attempt.

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 midpoint, at least one half of the array is 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. If not, move lo to mid + 1. Otherwise the right half is sorted, so run the mirror check. Return mid when you hit the target, and -1 when the loop ends. The common pitfall is the comparison. Use <= for the left-half check, or two-element windows break. Another is off-by-one on the range bounds. Test with [1] and target 0, and with a fully unrotated array. Distinct values mean you don't need duplicate handling. If your mind goes blank on the boundaries mid-assessment, StealthCoder can supply the working loop as a hedge.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

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 for the candidate who got the OA invite this morning and has 72 hours, not six months.

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

Capgemini reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Search in Rotated Sorted Array FAQ

How hard is Search in Rotated Sorted Array really?+

Medium. The idea is short, but the boundary checks trip people up. Most failures come from using < instead of <= when comparing nums[lo] to nums[mid], or from wrong bounds on the target range check. Once you've written it once, it's mechanical.

What's the trick for the Capgemini version?+

Find which half is sorted at each step, then check whether the target lies in that sorted half. Discard the other half. That keeps it O(log n), which the problem statement explicitly demands. A linear scan returns correct answers but violates the requirement.

Do I need to find the pivot first?+

No. You can do a two-pass approach, finding the pivot and then binary searching the right half. But the single-pass version is shorter and has fewer places to mess up. Pick whichever you can write without hesitating.

Which edge cases should I test?+

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 index 0, a target at the last index, and a target that's absent. The examples with [4,5,6,7,0,1,2] cover the standard rotated case.

How do I prepare in 48 hours?+

Write the solution from scratch three times without looking. Trace it by hand on [4,5,6,7,0,1,2] with targets 0 and 3. Then do a couple of plain binary search variants so the loop template is automatic. Focus on the sorted-half check, not on memorizing code.

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

OA at Capgemini?
Invisible during screen share
Get it