PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

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.

Return the moving average after each input value over the latest N 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 example.

Input: (1, [2,4,6])

Expected Output: [2.0, 4.0, 6.0]

Explanation: Window of one.

Input: (5, [])

Expected Output: []

Explanation: Empty stream.

Hints

  1. Model object-style prompts as operation streams when needed.
  2. Handle empty and boundary cases before the main logic.
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
  • 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)
  • Implement sliding-window rate limiter function - Atlassian (medium)
  • Implement sequential and parallel URL requests - Atlassian (medium)
  • Merge intervals and design rating APIs - Atlassian (medium)
  • Filter Invalid Data Events - Atlassian (easy)