Problem Description
Given an array of integers A of size N and an integer B.
array A is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2 ).
You are given a target value B to search. If found in the array, return its index, otherwise, return -1.
You may assume no duplicate exists in the array.
NOTE:- Array A was sorted in non-decreasing order before rotation.
Think about the case when there are duplicates. Does your current solution work? How does the time complexity change?
1 <= N <= 1000000
1 <= A[i] <= 10^9
1 <= B <= 10^9
all elements in A are distinct.
The first argument given is the integer array A.
The second argment given is the integer B.
Return index of B in array A, otherwise return -1
Input 1:
A = [4, 5, 6, 7, 0, 1, 2, 3] B = 4
Input 2:
A = [5, 17, 100, 3] B = 6
Output 1:
0
Output 2:
-1
Explanation 1:
Target 4 is found at index 0 in A.
Explanation 2:
Target 6 is found not found in the array A = [5, 17, 100, 3].
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.