← Bloomberg Interview Insights

Bloomberg·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Bloomberg SWE interview with a classic streaming data problem. Not much to say about the setup but the question itself kept me busy.

Questions Asked (1)

Q1

Given a continuous stream of numbers, design a data structure that can return the median at any point in time.

Algorithms & Data Structures
Author's notes

Two heaps.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use two heaps—a max-heap for the lower half and a min-heap for the upper half—to maintain the median in O(log n) insertion and O(1) retrieval. Explain the balancing logic and how to handle even and odd total counts.

Pro tip: Mention that this two-heap approach is the standard solution for streaming medians and is used in real-time systems like Bloomberg's market data feeds, where low-latency median calculation is critical.

1. Clarify requirements and constraints

Ask about the expected frequency of median queries, memory limits, and whether the stream is truly unbounded. This shows you consider practical trade-offs.

2. Propose the two-heap data structure

Describe using a max-heap for the lower half and a min-heap for the upper half. Explain that the heaps are kept balanced so their sizes differ by at most one.

3. Detail insertion and balancing

Walk through adding a number: push to the appropriate heap, then rebalance by moving the top element if sizes differ by more than one. Emphasize O(log n) time.

4. Explain median retrieval

If both heaps are equal size, median is the average of their tops; otherwise, it's the top of the larger heap. This is O(1) time.

5. Analyze complexity and edge cases

State time and space complexity, and discuss handling empty stream, single element, and duplicate values. Optionally mention alternatives like balanced BSTs.

Key Points to Mention

  • Two heaps: max-heap for lower half, min-heap for upper half
  • Balancing condition: sizes differ by at most 1
  • Insertion time O(log n), median retrieval O(1)
  • Space complexity O(n) for storing all elements
  • Handling even vs. odd number of elements
  • Edge cases: empty stream, single element, duplicates

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.