Loading...
Loading...
Loading...
A sorted shelf of distinct item numbers was rotated: some items from the front were moved to the back. Find the position of a requested number, or print -1, in logarithmic time.
Example 1
Input
7 4 5 6 7 0 1 2 0
Output
4
At position 4.
Example 2
Input
7 4 5 6 7 0 1 2 3
Output
-1
Try the problem first. Open one hint at a time.
At each step one half of the range is still in order.
Check whether the target lies in the ordered half; keep that half or throw it away.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor