LFU Cache for Map Tile Requests With Recency Tie-Breaks

Last updated: November 29, 2026

Quick Overview

Implement a fixed-capacity cache for map tiles with get(key) and put(key, value) in O(1). When full, evict the least frequently used tile, and among those with equal frequency evict the least recently used one.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Implement a fixed-capacity cache for map tiles with get(key) and put(key, value) in O(1). When full, evict the least frequently used tile, and among those with equal frequency evict the least recently used one.

An Uber onsite design-a-data-structure problem related to caching map tiles on edge servers, where popularity matters more than recency. It is harder than LRU because frequency and recency must both be tracked in O(1).

What the Interviewer Expects
  • Keeps key to (value, frequency) and frequency to ordered keys
  • Tracks the minimum frequency for O(1) eviction
  • Moves a key to the next frequency bucket on access
  • Resets minimum frequency to 1 on new inserts
  • Handles capacity zero and updates to existing keys
Key Topics to Cover
design a data structure
LFU cache
hash map
ordered dict
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 age frequencies so old popular tiles can be evicted?
  • Compare LFU and LRU hit rates for map tile traffic.
  • How would you make this thread-safe without a global lock?
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
  • get(key): return value or -1, and count as a use.
  • put(key, value): insert or update (an update counts as a use); evict when over capacity.
  • Both operations O(1)....
High-Level Design

Use three structures. vals[key] = value, freq[key] = count, and buckets[count], an OrderedDict of keys in recency order for that count. min_freq tracks the smallest non-empty bucket. On a use,...


Submit Your Answer
Markdown supported