Find an Element in a Rotated Sorted Array
Medium

Problem Statement

Given a sorted array of distinct integers that has been rotated at an unknown pivot, and a target value, find the index of the target if it exists in the array. Otherwise, return -1.

Examples

1Example 1
Input:
{ "nums": [ 4, 5, 6, 7, 0, 1, 2 ], "target": 0 }
Output:
4
2Example 2
Input:
{ "nums": [ 4, 5, 6, 7, 0, 1, 2 ], "target": 3 }
Output:
-1
3Example 3
Input:
{ "nums": [ 1 ], "target": 0 }
Output:
-1
Loading...

Sign in to Run Code and Submit