As reported: Arista Networks technical round (2025): two DSA problems and Java theory questions; this was one of the two.
This is LeetCode 33 — Search in Rotated Sorted Array.
An array nums sorted in ascending order with distinct values has been rotated at an unknown index, e.g. [0,1,2,4,5,6,7] → [4,5,6,7,0,1,2]. Given target, return its index, or -1 if it is not present. The algorithm must run in O(log n).
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
Constraints: 1 ≤ nums.length ≤ 5000; −10^4 ≤ nums[i], target ≤ 10^4; values are distinct.
Code runner format: two lines — nums as a JSON array and target. Implement search(nums, target); the harness prints the index.