Compute a moving average on a stream
Company: Atlassian
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
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.
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
- Model object-style prompts as operation streams when needed.
- Handle empty and boundary cases before the main logic.