← Citadel Interview Insights

Citadel·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Citadel quant engineer interview with a pretty gnarly algorithmic problem about maintaining a running median under memory constraints. Not a lot of context given about the round or outcome but the problem itself was memorable enough to post about.

Questions Asked (1)

Q1

How would you implement a running (cumulative) median when memory is limited?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The classic two-heap approach came to mind immediately but they pushed back on memory usage pretty fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the constraints: what does 'limited memory' mean (e.g., fixed-size buffer, streaming data, no disk)? Then discuss approximate algorithms like the P² quantile estimator or reservoir sampling, and compare trade-offs between accuracy, memory, and update speed. Finally, propose a concrete implementation using a bounded data structure (e.g., two heaps with eviction) and explain how to handle the running median.

Pro tip: Mention that exact running median with limited memory is impossible for arbitrary data, so you must choose an approximation; showing awareness of this fundamental limit and then offering a practical solution demonstrates depth.

1. Clarify requirements and constraints

Ask about the data stream characteristics (size, distribution, order), memory limit (e.g., O(1), O(log n), fixed KB), and accuracy requirements (exact vs. approximate).

2. Discuss exact solutions and their memory needs

Explain that maintaining two heaps (max-heap for lower half, min-heap for upper half) gives O(n) memory, which may be too large; note that exact median requires storing all data in worst case.

3. Propose approximate algorithms

Introduce streaming quantile estimators like P² (for a single quantile) or t-digest, which use O(1) or O(log n) memory and provide bounded error; mention reservoir sampling as a baseline.

4. Compare trade-offs and choose an approach

Weigh memory usage, accuracy, update time, and implementation complexity; for example, P² uses constant memory and O(1) update, but may drift for non-stationary data.

5. Outline implementation details

Describe how to maintain the estimator: initialize with first few points, update markers based on incoming values, and periodically adjust to maintain quantile estimates.

Key Points to Mention

  • Exact running median requires O(n) memory (e.g., two heaps), which violates limited memory.
  • Approximate algorithms like P² quantile estimator or t-digest use constant or logarithmic memory.
  • Trade-offs: accuracy vs. memory vs. update speed; P² is simple but may not handle concept drift.
  • Reservoir sampling can provide a random sample for median estimation but has high variance.
  • For fixed-size memory, consider a bounded buffer with eviction (e.g., sliding window) if data is stationary.
  • Mention that the median is a special case of quantile estimation (50th percentile).

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