PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Atlassian

Design O(1) cache and moving average

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in data structures and streaming algorithms by combining an O(1) cache design with an eviction policy and a fixed-window moving-average for value streams, measuring competency in time/space complexity, stateful in-memory data handling, and algorithmic correctness.

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

Design O(1) cache and moving average

Company: Atlassian

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Problem You are asked two coding questions: ### 1) O(1) cache data structure Design a data structure that supports the following operations in **O(1)** average time: - `get(key) -> value` (return a sentinel such as `-1`/`null` if missing) - `put(key, value)` Assume the cache has a fixed capacity `C`. When inserting a new key and the cache is full, it must evict one existing entry according to a well-defined policy (state the policy you choose, e.g., least-recently-used). ### 2) Moving window average Implement a structure that receives a stream of numbers and returns the average of the **last K values** each time a new value arrives: - initialize with window size `K` - `next(x) -> average_of_last_up_to_K_values` If fewer than `K` values have been seen, average over all values so far. ## Constraints - Aim for O(1) per operation time. - Use standard in-memory data structures.

Quick Answer: This question evaluates proficiency in data structures and streaming algorithms by combining an O(1) cache design with an eviction policy and a fixed-window moving-average for value streams, measuring competency in time/space complexity, stateful in-memory data handling, and algorithmic correctness.

Related Interview Questions

  • Compute a moving average on a stream - Atlassian (hard)
  • Find a secret word using match feedback - Atlassian (hard)
  • Implement sliding-window rate limiter function - Atlassian (medium)
  • Merge intervals and design rating APIs - Atlassian (medium)
  • Implement sequential and parallel URL requests - Atlassian (medium)
Atlassian logo
Atlassian
Jan 22, 2026, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
3
0
Loading...

Problem

You are asked two coding questions:

1) O(1) cache data structure

Design a data structure that supports the following operations in O(1) average time:

  • get(key) -> value (return a sentinel such as -1 / null if missing)
  • put(key, value)

Assume the cache has a fixed capacity C. When inserting a new key and the cache is full, it must evict one existing entry according to a well-defined policy (state the policy you choose, e.g., least-recently-used).

2) Moving window average

Implement a structure that receives a stream of numbers and returns the average of the last K values each time a new value arrives:

  • initialize with window size K
  • next(x) -> average_of_last_up_to_K_values

If fewer than K values have been seen, average over all values so far.

Constraints

  • Aim for O(1) per operation time.
  • Use standard in-memory data structures.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Atlassian•More Machine Learning Engineer•Atlassian Machine Learning Engineer•Atlassian Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.