Maintain a Stream Median
Company: Ixl
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: This question evaluates the ability to design and implement efficient online data structures and algorithms for maintaining dynamic order statistics and computing the median of a stream of integers.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([['add',1], ['add',2], ['median'], ['add',3], ['median']],)
Expected Output: [None, None, 1.5, None, 2.0]
Explanation: Odd and even medians.
Input: ([['median'], ['add',-1], ['median']],)
Expected Output: [None, None, -1.0]
Explanation: Empty query and negative value.
Input: ([['add',5], ['add',5], ['median']],)
Expected Output: [None, None, 5.0]
Explanation: Duplicates.
Hints
- Choose a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.