Search in Rotated Sorted Array

Medium
ArrayBinary SearchAmazonMeta
An ascending array of distinct integers was rotated at an unknown pivot. Given the rotated array and a target, print the zero-based index of the target, or -1 if it is not present. Input format: - First line: n target - Second line: n integers, the rotated array

Constraints

1 <= n <= 10^5
-10^9 <= nums[i], target <= 10^9
Values are distinct and form a rotation of an ascending array.

Sample tests

Sample 1

Sample 2

Sign in to submit