Data Structures & AlgorithmsHardProduct placement · Amazon/Microsoft
Binary search with mid = (lo + hi) // 2 (lo = 0, hi = n − 1, loop while lo ≤ hi) looks for 16 in [18, 39, 40, 44, 45, 56, 60, 62, 70, 84, 97]. Which elements are compared with the key, in order?
- A. 56, 40
- B. 56, 40, 18
- C. 56, 40, 39, 18
- D. 56, 40, 18, 39
Correct answer: B. 56, 40, 18
Each probe halves the range: 56 → 40 → 18. The range becomes empty, so the search fails after 3 probes.
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
- For the sorted array [3, 3, 4, 5, 5, 7, 7, 8, 8, 8, 8, 10] (0-based), what are lowerbound(5) (first index with value ≥ 5) and…
- How many contiguous subarrays of [−2, 1, −3, −4, 8, 1, 4, −5, 6] have a sum divisible by 3? (Count equal prefix-sum remainders.)
- What does this loop-counting code print? (Python) python n, c = 16, 0 i = 2 while i <= n: c += 1 i = i i print(c)
- An equilibrium index i has (sum of elements left of i) = (sum of elements right of i), excluding a[i]. Which indices of [0, 9, 2, 3, 4, 2…
- A stack is implemented with two queues where push is costly (new element goes into the empty queue, then everything else is moved behind…
- Daily prices are [15, 17, 19, 13, 20, 17, 38, 38, 40]. What is the maximum profit with at most ONE buy and one later sell, and with…