LRU Price Quote Cache With Per-Entry Expiry

Last updated: November 29, 2026

Quick Overview

Implement a fixed-capacity cache of price quotes that evicts the least recently used entry when full and treats any quote older than its time to live as missing.

Coinbase
Coding & Algorithms
Software Engineer
Coinbase
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Implement a fixed-capacity cache of price quotes that evicts the least recently used entry when full and treats any quote older than its time to live as missing.

Quotes shown on Coinbase's buy screen must be fresh, and serving a stale price is worse than a cache miss. The interviewer wants a hand-built hash map plus doubly linked list with sentinels, O(1) operations and correct interaction between TTL and LRU order.

What the Interviewer Expects
  • Combine a hash map with a doubly linked list for O(1) get and put
  • Use sentinel head and tail nodes to avoid null checks
  • Check expiry on read and remove stale entries
  • Refresh both value and expiry on update
  • Explain why OrderedDict works but the interviewer may want the manual version
Key Topics to Cover
linked lists
hashing
LRU cache
TTL
design a data structure
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Expired entries that are never read still use capacity; how would you reclaim them?
  • How would you make this thread-safe without a global lock?
  • How would you serve a slightly stale quote while refreshing in the background?
  • How would you size TTL per asset based on volatility?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

put(key, value, now) and get(key, now). Capacity is fixed; the least recently used entry goes first when full. An entry put at time t is valid while now < t + ttl. Time is passed in for testabil...

High-Level Design

The map points keys to list nodes. The list orders nodes from most recent (after head) to least recent (before tail). get unlinks and re-pushes a live node to the front, or removes an expired one. put...


Submit Your Answer
Markdown supported