ALG-M008MediumBinary Search
Find in a Rotated Log
A strictly increasing array was rotated around a pivot. Return the index of target, or -1 when absent. All values are distinct.
Contract
input numbers: integer[]
input target: integer
return integer
Constraints
- • Distinct values
- • Array is a rotated strictly increasing sequence
Examples
Example 1
numbers = [4, 5, 6, 7, 0, 1, 2]
target = 0
→ 4
Example 2
numbers = [4, 5, 6, 7, 0, 1, 2]
target = 3
→ -1
5 judge tests (2 shown above). Target complexity: O(log n).