A sorted array of distinct integers has had some adjacent pairs swapped, so each element is at most one position away from where it belongs. Find the index of a given element, or -1, in O(log n).
You've read your 3 free write-ups
Sign up free to keep reading. Your account opens the first 10 questions of every company.