PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Google

Maintain streaming median and loosemedian

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of online streaming algorithms, running-median maintenance, and bit-level computations for identifying logarithmic intervals (the 'loose median').

  • Medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Maintain streaming median and loosemedian

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Design a data structure for an online stream of positive integers supporting insert (x). After each insertion, output: (a) the median of all values seen so far (for an even count, define the median as the average of the two middle values); and (b) the 'loose median' interval [2^k, 2^(k+ 1)] where k is the unique integer satisfying 2^k < median < 2^(k+ 1). Describe the algorithms and data structures, their time and space complexities, and how to implement bit operations to compute 2^k from the median. Discuss how you would handle boundary cases (e.g., median equals a power of two, zero/negative numbers, or non-integer medians).

Quick Answer: This question evaluates understanding of online streaming algorithms, running-median maintenance, and bit-level computations for identifying logarithmic intervals (the 'loose median').

Related Interview Questions

  • Solve Flower Placement and Directory Deletion - Google (medium)
  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Implement Checksums and Feature Rollout Evaluation - Google (medium)
Google logo
Google
Aug 8, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
5
0

Design a data structure for an online stream of positive integers supporting insert (x). After each insertion, output: (a) the median of all values seen so far (for an even count, define the median as the average of the two middle values); and (b) the 'loose median' interval [2^k, 2^(k+ 1)] where k is the unique integer satisfying 2^k < median < 2^(k+ 1). Describe the algorithms and data structures, their time and space complexities, and how to implement bit operations to compute 2^k from the median. Discuss how you would handle boundary cases (e.g., median equals a power of two, zero/negative numbers, or non-integer medians).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google 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.