LRU Cache for Expensive Point-in-Time Factor Computations

Last updated: November 29, 2026

Quick Overview

Implement an LRU cache in front of a function that computes a factor's values for a given date, with a fixed capacity, hit and miss counters, and invalidation of one factor's entries.

Voleon
Software Engineering Fundamentals
Software Engineer
Voleon
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


Implement an LRU cache in front of a function that computes a factor's values for a given date, with a fixed capacity, hit and miss counters, and invalidation of one factor's entries.

Researchers at Voleon recompute the same factor slices repeatedly during interactive work, so caching is a practical memory and performance topic. The interviewer checks that you pick an O(1) structure, evict correctly, and think about invalidation and memory limits.

What the Interviewer Expects
  • Choose an ordered hash map or hash map plus doubly linked list
  • Make get and insert O(1)
  • Evict the least recently used entry when over capacity
  • Support targeted invalidation
  • Discuss sizing by memory rather than entry count
Key Topics to Cover
LRU cache
hash maps
eviction policy
memoization
memory management
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you bound the cache by bytes instead of entries?
  • How would you make it safe for concurrent readers?
  • When would LRU be a bad eviction policy for backtests that scan dates in order?
Sharpen Your Skills on Codemia

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

Practice System Design Problems
Sample Answer
Requirements

Key (factor, date). On miss, call compute, store, and evict the least recently used entry if over capacity. On hit, mark the entry as most recently used. Expose hit and miss counts. `invalidate(fa...

High-Level Design

collections.OrderedDict keeps insertion order and supports move_to_end and popitem(last=False) in O(1), so it is exactly a hash map plus doubly linked list. Without it, you would build the linke...


Submit Your Answer
Markdown supported

Related Questions