PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Atlassian

Compute a moving average on a stream

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of streaming data structures, sliding-window aggregation, and the time/space trade-offs involved in maintaining running statistics over recent inputs, testing algorithmic efficiency and numerical handling skills.

  • hard
  • Atlassian
  • Coding & Algorithms
  • Machine Learning Engineer

Compute a moving average on a stream

Company: Atlassian

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Design a data structure to compute the moving average over the last **N** values from a stream. ## Input/Operations - Initialize with an integer window size `N`. - Repeatedly receive values `x` (integers or floats). - After each new value arrives, return the average of the most recent `min(N, count_so_far)` values. ## Constraints/Expectations - Each update should be **O(1)** time. - Use **O(N)** memory. ## Example If `N = 3` and the stream is `1, 10, 3, 5`: - after 1 → 1.0 - after 10 → (1+10)/2 = 5.5 - after 3 → (1+10+3)/3 = 4.666... - after 5 → (10+3+5)/3 = 6.0

Quick Answer: This question evaluates understanding of streaming data structures, sliding-window aggregation, and the time/space trade-offs involved in maintaining running statistics over recent inputs, testing algorithmic efficiency and numerical handling skills.

Related Interview Questions

  • Find a secret word using match feedback - Atlassian (hard)
  • Implement sequential and parallel URL requests - Atlassian (medium)
  • Implement sliding-window rate limiter function - Atlassian (medium)
  • Merge intervals and design rating APIs - Atlassian (medium)
  • Filter Invalid Data Events - Atlassian (easy)
Atlassian logo
Atlassian
Mar 1, 2026, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
3
0
Loading...

Design a data structure to compute the moving average over the last N values from a stream.

Input/Operations

  • Initialize with an integer window size N .
  • Repeatedly receive values x (integers or floats).
  • After each new value arrives, return the average of the most recent min(N, count_so_far) values.

Constraints/Expectations

  • Each update should be O(1) time.
  • Use O(N) memory.

Example

If N = 3 and the stream is 1, 10, 3, 5:

  • after 1 → 1.0
  • after 10 → (1+10)/2 = 5.5
  • after 3 → (1+10+3)/3 = 4.666...
  • after 5 → (10+3+5)/3 = 6.0

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Atlassian•More Machine Learning Engineer•Atlassian Machine Learning Engineer•Atlassian 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.