24. Search in Rotated Sorted Array

nums is a sorted array of distinct values that has been rotated at an unknown pivot. Return the index of target, or -1. Required: O(log n).

Example 1

Input: nums = [5,6,7,1,2,3], target = 2
Output: 4

Example 2

Input: nums = [5,6,7,1,2,3], target = 8
Output: -1
Hint 1

At any mid, at least one half is sorted.

Hint 2

Check whether the target lies inside the sorted half; if not, search the other half.

Binary Search