Search in Rotated Sorted Array

Medium
Arrays Binary Search
Given a rotated sorted array and a target, return the index or -1. Input line 1: space-separated array Input line 2: target Output: index or -1

Constraints

1 <= nums.length <= 5000 -10000 <= nums[i], target <= 10000 All values are unique.

Examples

Example 1:
Input: 4 5 6 7 0 1 2 0
Output:
Example 2:
Input: 4 5 6 7 0 1 2 3
Output:

Hints

Modified binary search.
Determine which half is sorted.
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.