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?
- A. 4
- B. 0
- C. 5
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Array [56, 73, 74, 82, 90, 3, 48] is a sorted array rotated at pivot 2. Using the standard O(log n) rotated-array binary search (decide…
- The Boyer–Moore majority vote algorithm (candidate/counter, no verification pass) runs on [1, 5, 5, 2, 5, 1, 5, 5]. What candidate and…
- The Boyer–Moore majority vote algorithm (candidate/counter, no verification pass) runs on [6, 4, 4, 4, 6, 4, 6, 2]. What candidate and…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- A min-stack (push/pop O(1), getMin O(1) via an auxiliary stack tracking the running minimum) runs this sequence in order: push(-3)…
- Heights [3, 6, 1, 4, 7, 9, 3, 7, 7, 4] represent vertical lines at each index. What is the maximum water area (min(height) × horizontal…