FastPrepSingle-Pass Search in a Rotated Sorted Array
Problems/Single-Pass Search in a Rotated Sorted Array

Single-Pass Search in a Rotated Sorted Array

eBay logoeBay● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report identifies the standard rotated-sorted-array search and explicitly requires a single-pass binary search with an overflow-safe midpoint.

An integer array nums was originally sorted in strictly increasing order and then rotated at an unknown pivot. Given nums and an integer target, return the index of target, or -1 if it is absent.

Use one binary-search loop. Do not first locate the pivot and then run a second binary search. Your solution must run in O(log n) time.

Function

searchRotated(nums: int[], target: int) → int

Examples

Example 1

nums = [4,5,6,7,0,1,2]target = 0return = 4

The target 0 is stored at index 4.

Example 2

nums = [4,5,6,7,0,1,2]target = 3return = -1

The target does not occur in the array.

Constraints

  • 1 <= nums.length <= 100000
  • -2147483648 <= nums[i], target <= 2147483647
  • All values in nums are distinct.
  • nums is a rotation of a strictly increasing array.

More eBay problems

  • Meeting Rooms IIPHONE SCREEN · Seen Oct 2026
  • Count Staircases with Strictly Increasing StepsONSITE INTERVIEW · Seen Oct 2026
  • Hierarchical Permission CheckONSITE INTERVIEW · Seen Oct 2026
All eBay interview questionsSee eBay hiring insights
Saved
class Solution {
    public int searchRotated(int[] nums, int target) {
        // Write your code here
    }
}
Checking account…