Compute moving average over last N stream
Company: Atlassian
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
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.
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.