Byte-Budgeted Map Tile Cache With Pinning
Last updated: November 29, 2026
Quick Overview
Design an LRU cache for HD map tiles with a byte capacity where tiles have different sizes and tiles currently used by a running simulation can be pinned (reference counted) so they are never evicted; put must fail cleanly if a tile cannot fit even after evicting every unpinned tile.
Applied Intuition
November 29, 20260
0
0 solved
Design an LRU cache for HD map tiles with a byte capacity where tiles have different sizes and tiles currently used by a running simulation can be pinned (reference counted) so they are never evicted; put must fail cleanly if a tile cannot fit even after evicting every unpinned tile.
Large-scale simulation at Applied Intuition streams HD map tiles around many vehicles, so a size-aware cache with pinning is a realistic component. The interviewer looks for O(1) operations, correct accounting of pinned bytes, and no infinite eviction loops.
What the Interviewer Expects
- Keep unpinned tiles in an OrderedDict for O(1) LRU operations
- Keep pinned tiles out of the eviction list with a pin count
- Track total bytes and pinned bytes separately
- Reject puts that cannot fit before evicting anything
- Handle updates to existing keys, both pinned and unpinned
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you make this thread safe for many simulation workers?
- How would you prefetch tiles along the ego's planned route?
- How would you switch the policy to evict by cost to reload rather than recency?
- What metrics would you expose to tune the capacity?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
get, put(tile_id, data, size), pin, unpin. Capacity is in bytes. Pinning is reference counted: two simulations can pin one tile. On the final unpin the tile becomes the most recently used. A f...
High-Level Design
Two containers: an OrderedDict of unpinned tiles in LRU order and a dict of pinned tiles with counts. Eviction pops from the front of the LRU only, so pinned tiles are never touched. The key insight...
Submit Your Answer
Applied Intuition Software Engineer Interview Guide
Interview process, tips, and preparation timeline