loading…
A sorted list of distinct numbers was rotated, e.g. [4, 5, 6, 7, 0, 1, 2]. Write search_rotated(nums, target) returning the index of target or -1, in O(log n).
search_rotated([4, 5, 6, 7, 0, 1, 2], 0) -> 4
search_rotated([4, 5, 6, 7, 0, 1, 2], 3) -> -1
Stuck on the idea itself? The binary search lesson walks through the pattern from scratch.