There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k. Given the array nums after the possible rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums. You must write an algorithm with O(log n) runtime complexity.
Example 1
Input: nums = [4,5,6,7,0,1,2], target = 0
Output: 4
Explanation: The array [0,1,2,4,5,6,7] was rotated to start at 4. The target 0 now sits at index 4.
Example 2
Input: nums = [4,5,6,7,0,1,2], target = 3
Output: -1
Explanation: 3 would belong between 2 and 4, but it is not in the array, so the answer is -1.
Example 3
Input: nums = [1], target = 0
Output: -1
Explanation: The only element is 1, not 0, so the answer is -1.
In a rotated sorted array, at least one side of any midpoint is **fully sorted**. Identify that side; check whether `target` lies in its range; if yes search there, otherwise search the other half.
Run checks all cases above. Submit evaluates all test cases.