← Snapchat Interview Insights

Snapchat·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Snapchat SWE interview with a coding round that put a spin on the classic LRU cache problem. Not the hardest interview I've done but the twist tripped me up more than I expected.

Questions Asked (1)

Q1

Design an LRU cache where each item has its own size and the cache has a fixed total capacity. Evict least-recently-used items one by one until there's enough room to insert. Support get (marks as recently used) and put (reject if item size alone exceeds capacity).

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

I knew LRU cache cold, hashmap plus doubly linked list, move to front on access, evict from the tail.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and edge cases, then propose a hash map combined with a doubly linked list to track recency and sizes. Explain how eviction works by removing from the tail until there's enough capacity, and handle the put rejection when item size exceeds total capacity.

Pro tip: Mention that you can optimize eviction by maintaining a running total of used capacity and only evicting when necessary, avoiding O(n) scans. Also, discuss thread-safety considerations if the cache is shared, showing awareness of concurrent environments.

1. Clarify requirements and edge cases

Ask about expected operations, size constraints, concurrency needs, and behavior when item size exceeds capacity. Confirm that get should update recency and put should reject oversized items.

2. Choose data structures

Propose a hash map for O(1) access to nodes and a doubly linked list to maintain recency order, with each node storing key, value, and size. Track total used capacity.

3. Define get and put operations

For get: if key exists, move node to front (most recent) and return value; else return null. For put: if key exists, update value and size, adjust capacity, move to front; else create new node, add to front, and evict from tail until enough space.

4. Handle eviction and rejection

During put, if item size > total capacity, reject immediately. Otherwise, while used capacity + item size > total capacity, remove tail node (least recent) and update used capacity. Then insert new item.

5. Analyze complexity and trade-offs

Explain that both get and put are O(1) amortized due to hash map and linked list operations. Discuss potential optimizations like lazy eviction or using a priority queue, and trade-offs with concurrency.

Key Points to Mention

  • Use a hash map for O(1) key lookup and a doubly linked list for O(1) recency updates.
  • Track total used capacity to avoid scanning the entire cache during eviction.
  • Evict from the tail (least recently used) one by one until enough space.
  • Reject put if the item's size alone exceeds total capacity.
  • Update recency on both get and put operations.
  • Consider thread-safety and potential locking strategies if the cache is shared.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.