Byte-Budgeted LRU Cache for Home Screen Artwork Tiles

Last updated: November 29, 2026

Quick Overview

Design a cache for home screen poster images that holds at most capacity_bytes total, evicts least recently used images until a new one fits, and supports get(key) and put(key, size, data) in O(1) average time.

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

0

0

0 solved


Design a cache for home screen poster images that holds at most capacity_bytes total, evicts least recently used images until a new one fits, and supports get(key) and put(key, size, data) in O(1) average time.

Roku players range from low-memory sticks to TVs, and the home screen scrolls through rows of artwork that must stay smooth without running out of memory. The interviewer wants a size-aware LRU (not a count-based one) and checks handling of oversized items and updates to an existing key.

What the Interviewer Expects
  • Recognizes eviction must be by total bytes, not item count
  • Uses an ordered map or hash map plus doubly linked list for O(1) recency updates
  • Rejects an item larger than the whole budget without wiping the cache
  • Handles re-putting an existing key with a new size correctly
  • Keeps the used-bytes counter consistent through every path
Key Topics to Cover
LRU cache
Doubly linked list
Hash map
Memory budgeting
Embedded constraints
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
  • How would you pin artwork for the currently visible row so it is never evicted?
  • Would you evict by recency only, or weigh size and fetch cost (for example GreedyDual-Size)?
  • How do you make this safe if a decode thread and the render thread both access it?
  • How would you prefetch tiles for the row the user is scrolling toward?
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

Operations: get(key) returns the image and marks it most recently used, or None. put(key, size, data) inserts or replaces. Invariant: used <= capacity at all times. Clarifications: an image bi...

High-Level Design

A hash map from key to node plus a recency list gives O(1) lookups and moves. In Python, OrderedDict provides both: move_to_end on access and popitem(last=False) to evict the oldest. Track `used...


Submit Your Answer
Markdown supported

Related Questions