The problem. An ascending array of distinct integers was rotated at an unknown index (for example [0, 1, 2, 4, 5, 6, 7] became [4, 5, 6, 7, 0, 1, 2]). Given the rotated array nums and a target, return the target's index, or -1 if it isn't there. Your algorithm must run in O(log n) time.
nums = [4, 5, 6, 7, 0, 1, 2], target = 0 -> 4
nums = [4, 5, 6, 7, 0, 1, 2], target = 3 -> -1
nums = [1], target = 0 -> -1Members only · free account
The rest of this lesson, with 7 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson