Search a Shifted Sorted Array
An ascending array of distinct integers was rotated at some unknown point, so [1, 3, 5, 7, 9] might become [7, 9, 1, 3, 5]. Given the rotated array nums and a value x, return the index of x, or -1 if it is not present.
Your solution must run in O(log n) time.
Example 1
Input: nums = [7, 9, 1, 3, 5], x = 3 Output: 3
Example 2
Input: nums = [7, 9, 1, 3, 5], x = 8 Output: -1
Constraints
- 1 <= nums.length <= 10^5
- All values are distinct.
Hint 1
At any midpoint, at least one half of the range is sorted normally.
Hint 2
Check whether x lies inside the sorted half to decide which way to go.
Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Game Developer, Automation Test Engineer, Database Administrator
Run checks your code on 2 sample tests. Submit runs all 8 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.