Data Structures & AlgorithmsVery hardProduct Company SDE · Amazon OA

Problem: Two heaps are maintained over the stream 5, 15, 1, 3, 8, 7, 9, 10, 6, 11 to report the median after each element (lower median for even counts). What is the sum of the medians reported after each arrival?

  1. A. 72
  2. B. 56
  3. C. 64
  4. D. 51

Correct answer: B. 56

Lower medians after each arrival: 5, 5, 5, 3, 5, 5, 7, 7, 7, 7, summing to 56. Using the upper median for even counts gives 72, averaging the two middle values gives 64, and skipping the first arrival gives 51.

More Coding Interview Problems questions

Exams that ask this topic