Data Structures & AlgorithmsHardAmazon/Microsoft SDE pattern

Array [87, 4, 31, 36, 38, 63, 75] is a sorted array rotated at pivot 6. Using the standard O(log n) rotated-array binary search (decide which half is sorted, then check if the target lies in it), at what index is 38 found?

  1. A. 4
  2. B. 0
  3. C. 5
  4. D. 3

Correct answer: A. 4

At each step one half (low..mid or mid..high) is guaranteed sorted; checking whether the target falls in that sorted half's range decides which half to keep. Tracing this on the array places 38 at index 4.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic