Data Structures & AlgorithmsHardGoldman Sachs OA · LeetCode medium-hard

Array [90, 6, 26, 27, 39, 47, 79] 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 27 found?

  1. A. 4
  2. B. 2
  3. C. 3
  4. D. 6

Correct answer: C. 3

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 27 at index 3.

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

Exams that ask this topic