Gamified challenge · Modified binary search
The vault's drawers held distinct codes in increasing order, but the dial was turned: the list was cut at some point and the back part moved to the front. For example [0, 1, 2, 4, 5, 6, 7] may now read [4, 5, 6, 7, 0, 1, 2]. It may also not be turned at all.
Write search(nums, target) that returns the index of target in nums, or -1 if it isn't there. Aim for O(log n) probes: at any midpoint, at least one of the two halves is still sorted.
Example: search([4, 5, 6, 7, 0, 1, 2], 0) is 4, and search([4, 5, 6, 7, 0, 1, 2], 3) is -1.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google