PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Cognitiv

Maintain a Streaming Median

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of streaming algorithms and dynamic data structures for maintaining order statistics, along with analysis of time complexity and memory trade-offs.

  • medium
  • Cognitiv
  • Coding & Algorithms
  • Machine Learning Engineer

Maintain a Streaming Median

Company: Cognitiv

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are designing a component that receives integers one at a time and must return the current median after each update. Example: - After processing `[2, 3, 1]`, the median is `2`. - After processing one more value to form `[2, 3, 1, 4]`, the median is `(2 + 3) / 2 = 2.5`. Implement a data structure with two operations: - `add(x)`: insert an integer - `getMedian()`: return the median of all inserted values so far Discuss the time complexity of your approach. Follow-up: if the full input array is available up front and you want to avoid extra auxiliary space, how would you compute the median while minimizing additional memory usage?

Quick Answer: This question evaluates understanding of streaming algorithms and dynamic data structures for maintaining order statistics, along with analysis of time complexity and memory trade-offs.

Cognitiv logo
Cognitiv
Feb 9, 2026, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
3
0

You are designing a component that receives integers one at a time and must return the current median after each update.

Example:

  • After processing [2, 3, 1] , the median is 2 .
  • After processing one more value to form [2, 3, 1, 4] , the median is (2 + 3) / 2 = 2.5 .

Implement a data structure with two operations:

  • add(x) : insert an integer
  • getMedian() : return the median of all inserted values so far

Discuss the time complexity of your approach.

Follow-up: if the full input array is available up front and you want to avoid extra auxiliary space, how would you compute the median while minimizing additional memory usage?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Cognitiv•More Machine Learning Engineer•Cognitiv Machine Learning Engineer•Cognitiv Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ 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.