PracHub
QuestionsLearningGuidesInterview Prep
|Home/Software Engineering Fundamentals/Confluent

Design an LRU Cache with a Constant-Time Average

Last updated: Jul 22, 2026

Quick Overview

Design a fixed-capacity LRU cache whose get, put, and current-value average operations all run in expected constant time. Reason through map and recency-list invariants, running-sum updates, replacement and eviction edge cases, numeric precision, overflow, and tests that catch aggregate or ordering bugs.

  • medium
  • Confluent
  • Software Engineering Fundamentals
  • Software Engineer

Design an LRU Cache with a Constant-Time Average

Company: Confluent

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Onsite

# Design an LRU Cache with a Constant-Time Average Design an in-memory cache with fixed positive capacity. Keys are unique strings and values are signed numbers. Support: - `get(key)`: return the value and mark the key most recently used, or report a miss. - `put(key, value)`: insert or update the key and mark it most recently used; if over capacity, evict the least recently used key. - `get_average()`: return the arithmetic mean of values currently in the cache, or a documented empty result. All three operations should take expected `O(1)` time. Explain invariants, numeric choices, and edge cases rather than relying on an ordered-map library as a black box. ### Constraints & Assumptions - Capacity never changes after construction. - Updating an existing key replaces its value and changes recency. - The average covers current entries, not historical requests. - Thread safety is not required for the initial design. ### Clarifying Questions to Ask - Are values integers or floating point, and what precision is expected? - Does a miss change recency or affect the average? - What should `get_average` return for an empty cache? - Are overflow and concurrent calls in scope? ### What a Strong Answer Covers - A hash map paired with a doubly linked recency list - A running sum updated on insert, replacement, and eviction - Correct movement, unlinking, and eviction invariants - Expected-time, space, precision, and overflow analysis - Tests that check both recency and aggregate correctness ### Follow-up Questions - How would you add TTL expiration without scanning the cache? - How would a dynamic capacity change work? - How would you make operations thread-safe and linearizable? - What changes if values are vectors rather than scalars?

Quick Answer: Design a fixed-capacity LRU cache whose get, put, and current-value average operations all run in expected constant time. Reason through map and recency-list invariants, running-sum updates, replacement and eviction edge cases, numeric precision, overflow, and tests that catch aggregate or ordering bugs.

Related Interview Questions

  • Implement tail -n for a Very Large File - Confluent (medium)
  • Search Words and Phrases in a Large Line-Oriented File - Confluent (medium)
  • Explain Linux Command Execution, Filesystems, and Isolation - Confluent (medium)
  • Explain variadic functions - Confluent (hard)
|Home/Software Engineering Fundamentals/Confluent

Design an LRU Cache with a Constant-Time Average

Confluent logo
Confluent
Jan 1, 2026, 12:00 AM
mediumSoftware EngineerOnsiteSoftware Engineering Fundamentals
1
0

Design an LRU Cache with a Constant-Time Average

Design an in-memory cache with fixed positive capacity. Keys are unique strings and values are signed numbers. Support:

  • get(key) : return the value and mark the key most recently used, or report a miss.
  • put(key, value) : insert or update the key and mark it most recently used; if over capacity, evict the least recently used key.
  • get_average() : return the arithmetic mean of values currently in the cache, or a documented empty result.

All three operations should take expected O(1) time. Explain invariants, numeric choices, and edge cases rather than relying on an ordered-map library as a black box.

Constraints & Assumptions

  • Capacity never changes after construction.
  • Updating an existing key replaces its value and changes recency.
  • The average covers current entries, not historical requests.
  • Thread safety is not required for the initial design.

Clarifying Questions to Ask Guidance

  • Are values integers or floating point, and what precision is expected?
  • Does a miss change recency or affect the average?
  • What should get_average return for an empty cache?
  • Are overflow and concurrent calls in scope?

What a Strong Answer Covers Guidance

  • A hash map paired with a doubly linked recency list
  • A running sum updated on insert, replacement, and eviction
  • Correct movement, unlinking, and eviction invariants
  • Expected-time, space, precision, and overflow analysis
  • Tests that check both recency and aggregate correctness

Follow-up Questions Guidance

  • How would you add TTL expiration without scanning the cache?
  • How would a dynamic capacity change work?
  • How would you make operations thread-safe and linearizable?
  • What changes if values are vectors rather than scalars?
Loading comments...

Browse More Questions

More Software Engineering Fundamentals•More Confluent•More Software Engineer•Confluent Software Engineer•Confluent Software Engineering Fundamentals•Software Engineer Software Engineering Fundamentals

Write your answer

Your first approved answer each day earns 20 XP.

Sign in to write your answer.
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

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.