PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of streaming algorithms and sliding-window aggregation within the Coding & Algorithms domain, focusing on incremental computation, state management, and numerical stability when computing moving averages.

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

Compute moving average over last N stream

Company: Atlassian

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given an integer N and an unbounded stream of integers arriving one by one. After each new integer arrives, output the average of the last N integers seen so far. Requirements: - If fewer than N integers have arrived, average over all integers seen so far. - The solution should support efficient updates per element. Follow-up: - How would you modify the design if more recent numbers should have higher weight (e.g., exponentially decaying weights or a custom weight vector over the last N items)?

Quick Answer: This question evaluates understanding of streaming algorithms and sliding-window aggregation within the Coding & Algorithms domain, focusing on incremental computation, state management, and numerical stability when computing moving averages.

After each stream value, return the average of the last N values, or all seen values if fewer than N.

Examples

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

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

Explanation: Window grows then slides.

Input: (1, [4, 5])

Expected Output: [4.0, 5.0]

Explanation: Only latest value.

Input: (5, [])

Expected Output: []

Explanation: Empty stream.

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)