Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA

Two sorted arrays A = [1, 4, 7, 9] and B = [2, 3, 8, 10, 12] are merged in sorted order with two pointers. What is the 6th smallest element of the merged array?

  1. A. 7
  2. B. 9
  3. C. 4
  4. D. 8

Correct answer: D. 8

Advance the pointer whose head is smaller and count each step. The merged order is [1, 2, 3, 4, 7, 8, 9, 10, 12], so the 6th element is 8; off-by-one counting gives the neighbouring values.

More Coding Interview Problems questions

Exams that ask this topic