Anonymous · shared experience20 Jul 2025 · 5 views
Citadel: Running median with insert and findMedian
Problem. Design a structure with two operations: insert an integer, and return the median of everything inserted so far.
Expected path. Start with a list that is sorted when asked, then improve to two heaps: a max-heap for the lower half and a min-heap for the upper half, rebalanced after each insert. That gives O(log n) insert and O(1) median.
What went wrong. The candidate had working optimal code but forgot to handle a median request on an empty stream, and was rejected. Cover the empty and single-element cases out loud.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.