As reported: Goldman Sachs rounds (2025): finding an integer in a rotated sorted array in a 30-minute CoderPad (Associate, Transaction Banking; solved optimally); Search in Rotated Sorted Array in a DSA round of a frontend Associate loop held on CoderPad.
A sorted array of distinct integers was rotated at an unknown pivot (e.g. [4,5,6,7,0,1,2]). Return the index of target, or -1, in O(log n) time.
This is LeetCode 33 — Search in Rotated Sorted Array.
Example 1
nums = [4,5,6,7,0,1,2], target = 0
-> 4
Example 2
nums = [4,5,6,7,0,1,2], target = 3
-> -1
Example 3
nums = [1], target = 0
-> -1
Constraints: 1 ≤ n ≤ 5000; values distinct, -10^4 ≤ nums[i], target ≤ 10^4.
Code runner format: one JSON value per line: nums, then target (LeetCode's test-case format). Implement search(nums, target); the harness prints the result as JSON.