Search in Rotated Sorted Array

Given an integer array nums containing distinct values, where nums was strictly increasing before it was rotated at an unknown pivot, return the zero-based…

Given an integer array `nums` containing distinct values, where `nums` was strictly increasing before it was rotated at an unknown pivot, return the zero-based index of `target`. Return `-1` when `target` is absent. The array may be rotated zero times. Your solution must run in `O(log n)` time.

- `1 <= nums.length <= 5000` - `-10^4 <= nums[i], target <= 10^4` - Every value in `nums` is distinct. - `nums` is a rotation, possibly by zero positions, of a strictly ascending array.

Example 1: input nums = [4,5,6,7,0,1,2], target = 0; output 4. The value 0 is at zero-based index 4, after the rotation pivot.

Example 2: input nums = [4,5,6,7,0,1,2], target = 3; output -1. Every candidate half is eliminated without finding 3.

Example 3: input nums = [1], target = 1; output 0. The only value matches, so its zero-based index is 0.

Category: Binary Search. Topic: binary-search. Difficulty: Medium. Patterns: binary-search.