PracHub
QuestionsCoachesLearningGuidesInterview Prep

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.

O(1) LRU Cache Operations

Simulate an LRU cache with get/put operations and return get results. Missing keys return -1.

Constraints

  • Capacity is fixed

Examples

Input: (2, [['put', 1, 1], ['put', 2, 2], ['get', 1], ['put', 3, 3], ['get', 2]])

Expected Output: [1, -1]

Input: (0, [['put', 1, 1], ['get', 1]])

Expected Output: [-1]

Hints

  1. Use a map plus recency order.

Moving Window Average

Given window size K and a stream of values, return the average of the last up-to-K values after each new value.

Constraints

  • K > 0 in normal inputs

Examples

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

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

Input: (1, [4, 7])

Expected Output: [4.0, 7.0]

Input: (5, [])

Expected Output: []

Hints

  1. Maintain a queue and running sum.
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)