PracHub
QuestionsCoachesLearningGuidesInterview Prep

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.

Moving Average Over Last X Values

Return the moving average after each stream value over the latest X values.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: (3, [1,10,3,5])

Expected Output: [1.0, 5.5, 4.666667, 6.0]

Explanation: Prompt-style moving average.

Input: (1, [2,4])

Expected Output: [2.0, 4.0]

Explanation: Window one.

Hints

  1. Use deterministic tie-breaking for prompts with multiple valid outputs.
  2. For design-style APIs, simulate operations with explicit inputs.

Weighted Moving Average Over Last X Values

Return weighted moving average after each stream value using weights 1..k from oldest to newest.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: (3, [1,10,3,5])

Expected Output: [1.0, 7.0, 5.0, 5.166667]

Explanation: Weighted latest values higher.

Input: (2, [4])

Expected Output: [4.0]

Explanation: Single value.

Hints

  1. Use deterministic tie-breaking for prompts with multiple valid outputs.
  2. For design-style APIs, simulate operations with explicit inputs.
Last updated: Jun 27, 2026

Loading coding console...

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
  • AI Coding 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.

Related Coding Questions

  • Find a secret word using match feedback - Atlassian (hard)
  • Compute a moving average on a stream - Atlassian (hard)
  • Implement sliding-window rate limiter function - Atlassian (medium)
  • Implement sequential and parallel URL requests - Atlassian (medium)
  • Merge intervals and design rating APIs - Atlassian (medium)