Search a Rotated List
A list of distinct integers was sorted from smallest to largest, then rotated: cut at some point, with the second part moved to the front. [1, 3, 5, 8, 9, 12] rotated at 8 becomes [8, 9, 12, 1, 3, 5].
Given the rotated list nums and a target, return the index of target, or -1 if it is not in the list. You do not know where the cut was.
Examples
nums = [8, 9, 12, 1, 3, 5], target = 1 → 3
nums = [8, 9, 12, 1, 3, 5], target = 7 → -1
nums = [4], target = 4 → 0Constraints
- Between 1 and 100,000 distinct numbers, sorted and then rotated (possibly by zero).
- Aim for O(log n): reading the list from the start is O(n).
Console
›Run to see what your code prints
Run checks the 3 visible cases here, in your browser. Submit runs all 7 on the judge, 4 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.