As reported: Salesforce MTS loop (India, 2025), DSA round 1: Rotting Oranges, then this question.
This is LeetCode 33 — Search in Rotated Sorted Array.
An ascending array of distinct integers was rotated at an unknown pivot (for example [0,1,2,4,5,6,7] became [4,5,6,7,0,1,2]). Given the rotated array nums and target, return the index of target, or -1 if it is not there. Your algorithm must run in O(log n).
Example 1
nums = [4,5,6,7,0,1,2], target = 0
Output: 4
Example 2
nums = [4,5,6,7,0,1,2], target = 3
Output: -1
Example 3
nums = [1], target = 0
Output: -1
Constraints: 1 ≤ nums.length ≤ 5000; -10^4 ≤ nums[i], target ≤ 10^4; values are distinct.
Code runner format: one JSON value per line: nums, then target. Implement search(nums, target); the harness prints the index.