← Atlassian Interview Insights

Atlassian·Machine Learning Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Interviewed for an ML Engineer role at Atlassian and got a coding question that looks deceptively simple on the surface. The key was knowing the right data structure going in, otherwise you end up with an O(n) solution and a quiet room.

Questions Asked (1)

Q1

Implement a MovingAverage class that computes the rolling average of the last k values from a continuous data stream, with O(1) time per insertion.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew the circular buffer approach but blanked on articulating why it was O(1) for a second.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements: the class should maintain a rolling average of the last k values from a stream, with O(1) time per insertion. Use a circular buffer (or queue) to store the last k values and maintain a running sum to compute the average in constant time. Discuss edge cases such as when fewer than k values have been seen and how to handle k=0.

Pro tip: Mention that you would use a fixed-size array for the circular buffer to avoid the overhead of dynamic resizing, and emphasize that this design is thread-safe if needed by using locks or atomic operations, which is crucial in ML pipelines where data streams may be concurrent.

1. Clarify Requirements

Ask about the expected input types, whether k is fixed, and how to handle the initial phase when fewer than k values are available. Confirm that O(1) time per insertion is required and that space complexity should be O(k).

2. Design Data Structures

Choose a circular buffer (array of size k) to store the last k values and a variable to maintain the running sum. Explain that this allows O(1) updates by replacing the oldest value with the new one and adjusting the sum accordingly.

3. Implement Insertion Logic

Describe the algorithm: if the buffer is full, subtract the oldest value from the sum, overwrite it with the new value, and add the new value to the sum. If not full, simply add the new value and increment the count. Then compute the average as sum divided by the current count (or k if full).

4. Handle Edge Cases

Discuss handling k=0 (return 0 or throw exception), negative k, and non-numeric inputs. Also mention how to handle the initial period when the buffer isn't full, ensuring the average is computed over the available values.

5. Analyze Complexity and Trade-offs

State that time complexity per insertion is O(1) and space is O(k). Compare with alternative approaches like using a queue with O(1) amortized time or a linked list, and explain why the circular buffer is optimal for fixed k.

Key Points to Mention

  • Circular buffer implementation for O(1) insertion and O(k) space
  • Maintaining a running sum to avoid O(k) recomputation
  • Handling the initial phase when fewer than k values have been inserted
  • Edge cases: k=0, negative k, and non-numeric inputs
  • Thread safety considerations for concurrent data streams
  • Time and space complexity analysis: O(1) per insertion, O(k) space

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.