Interview Query

Target Value Search

Upvote
0
Downvote
Save
Mark Completed
Have you seen this question before?

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

You are given a target value to search. If found in the array return its index, otherwise return -1

Note: You may assume no duplicate exists in the array.

Bonus: Your algorithm’s runtime complexity should be in the order of O(logn)O(\log n).

Example:

Input: 

sample_input = [0,1,2,4,5,6,7]  
rotated_input = [4,5,6,7,0,1,2]
target_value = 6

Output:

def target_value_search(rotated_input,target_values) -> 2
Next question: Choosing k
.....
Loading editor
Use Shift + Enter to run

Comments

Loading comments