Data Structures & AlgorithmsHardProduct-company MCQ pattern
Array [85, 11, 19, 30, 40, 43, 70] 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 40 found?
- A. 5
- B. 3
- C. 4
- D. 0
Correct answer: C. 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 40 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
- A min-stack (push/pop O(1), getMin O(1) via an auxiliary stack tracking the running minimum) runs this sequence in order: push(-2)…
- Array [1, 2, 3, 4, 5, 6, 7, 8, 9] is left-rotated by d = 6 positions using the reversal algorithm (reverse first d, reverse rest, reverse…
- An LRU cache of capacity 3 runs this sequence of operations in order: put(4, 40), put(2, 20), put(5, 50), put(1, 10), put(1, 10), put(2…
- What is the postfix (Reverse Polish) form of the infix expression "(i + j) d - b / h", built with the standard stack-based conversion (^…
- Array [61, 75, 77, 8, 27, 29, 31, 32, 47, 56] is a sorted array rotated at pivot 7. Using the standard O(log n) rotated-array binary…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…