PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Atlassian

Compute moving and weighted averages from a stream

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's understanding of streaming algorithms, sliding-window statistics, and resource-constrained data structure design for computing moving and weighted averages.

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

Compute moving and weighted averages from a stream

Company: Atlassian

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are processing a stream of numeric events (e.g., user activity counts). You are given a fixed window size `X`. ## Part 1: Moving average over last X values Design a data structure / function that supports: - `next(value) -> avg` where `avg` is the average of the **most recent `X` values** seen so far (or fewer than `X` if fewer values have arrived). ## Part 2 (follow-up): Weighted moving average Modify the approach to compute a **weighted moving average** over the most recent `X` values where **more recent values have higher weight**. For example, for the last `k <= X` values (oldest to newest): - weights could be `1, 2, ..., k` - weighted average = \(\frac{\sum_{i=1}^{k} i \cdot v_i}{\sum_{i=1}^{k} i}\) ### Constraint Do this **without storing all previous data points** (i.e., memory should not grow with the total stream length).

Quick Answer: This question evaluates a candidate's understanding of streaming algorithms, sliding-window statistics, and resource-constrained data structure design for computing moving and weighted averages.

Related Interview Questions

  • Find a secret word using match feedback - Atlassian (hard)
  • Compute a moving average on a stream - 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)
Atlassian logo
Atlassian
Oct 15, 2025, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
2
0
Loading...

You are processing a stream of numeric events (e.g., user activity counts). You are given a fixed window size X.

Part 1: Moving average over last X values

Design a data structure / function that supports:

  • next(value) -> avg

where avg is the average of the most recent X values seen so far (or fewer than X if fewer values have arrived).

Part 2 (follow-up): Weighted moving average

Modify the approach to compute a weighted moving average over the most recent X values where more recent values have higher weight.

For example, for the last k <= X values (oldest to newest):

  • weights could be 1, 2, ..., k
  • weighted average = ∑i=1ki⋅vi∑i=1ki\frac{\sum_{i=1}^{k} i \cdot v_i}{\sum_{i=1}^{k} i}∑i=1k​i∑i=1k​i⋅vi​​

Constraint

Do this without storing all previous data points (i.e., memory should not grow with the total stream length).

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.