CT053

Search Rotated Sorted Array

HardAcceptance: 0.0%

A sorted array of integers has been rotated an unknown number of times. Given this array and a target element, find the index of the element in faster than linear time. If not found, return -1. Input: first line n, second line n space-separated integers (rotated sorted), third line target. Output: index or -1.

Example 1:

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

Example 2:

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

Constraints:

1 <= n <= 10^5 All elements distinct -10^9 <= arr[i] <= 10^9

Tags:

binary-search array
Loading...
Test Cases:No test cases
No test cases available.
Coding Problem Not Found | CodeTikki