PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Trexquant

Maintain median of a data stream

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in streaming data aggregation, dynamic order-statistics maintenance, and algorithmic complexity analysis for insertion and query operations.

  • medium
  • Trexquant
  • Coding & Algorithms
  • Software Engineer

Maintain median of a data stream

Company: Trexquant

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Design a data structure that supports: - `addNum(int x)`: Add an integer from a stream. - `findMedian()`: Return the median of all inserted numbers so far. Median definition: - If the count is odd: the middle element after sorting. - If the count is even: average of the two middle elements. ### Requirements - Aim for `O(log n)` per insertion and `O(1)` (or `O(log n)`) per median query. - Implement in C++. ### Constraints - Up to ~10^5 insertions/queries. - Values may be negative and can repeat.

Quick Answer: This question evaluates proficiency in streaming data aggregation, dynamic order-statistics maintenance, and algorithmic complexity analysis for insertion and query operations.

Related Interview Questions

  • Implement Trie search with wildcard matching - Trexquant (medium)
Trexquant logo
Trexquant
Sep 1, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
5
0

Design a data structure that supports:

  • addNum(int x) : Add an integer from a stream.
  • findMedian() : Return the median of all inserted numbers so far.

Median definition:

  • If the count is odd: the middle element after sorting.
  • If the count is even: average of the two middle elements.

Requirements

  • Aim for O(log n) per insertion and O(1) (or O(log n) ) per median query.
  • Implement in C++.

Constraints

  • Up to ~10^5 insertions/queries.
  • Values may be negative and can repeat.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Trexquant•More Software Engineer•Trexquant Software Engineer•Trexquant Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.