Maintain median of a data stream
Company: Trexquant
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates proficiency in streaming data aggregation, dynamic order-statistics maintenance, and algorithmic complexity analysis for insertion and query operations.
Read the full Trexquant Software Engineer interview experience this question came from
Constraints
- Values may repeat and may be negative
Examples
Input: ([1, 2, 3],)
Expected Output: [1.0, 1.5, 2.0]
Explanation: Increasing stream.
Input: ([5, 15, 1, 3],)
Expected Output: [5.0, 10.0, 5.0, 4.0]
Explanation: Even and odd counts.
Hints
- Maintain a max-heap for the lower half and a min-heap for the upper half.