Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Latest commit

 

History

History
executable file
·
21 lines (11 loc) · 703 Bytes

Shifted_Binary_Search.md

File metadata and controls

executable file
·
21 lines (11 loc) · 703 Bytes

Shifted Binary Search

Problem Statement

Write a function that takes in a sorted array of integers as well as a target integer. The caveat is that the numbers in the array have been shifted by some amount; in other words, they have been moved to the left or the right by one or more positions. For example, [1, 2, 3, 4] might become [3, 4, 1, 2]. The function should use a variation of the Binary Search algorithm to nd if the target number is contained in the array and should return its index if it is, otherwise -1.

Sample input: [45, 61, 71, 72, 73, 0, 1, 21, 33, 45], 33 Sample output: 8

Explanation

Solution

Check this Python code.