← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Google SWE interview with a classic LRU cache problem, but with a twist that includes a delete operation on top of the usual get and put. Felt pretty solid on the concept but the delete requirement caught me slightly off guard since most practice problems don't include it.

Questions Asked (1)

Q1

Design and implement an LRU cache with get, put, and delete operations, all in O(1) time complexity. Include a constructor, test cases, and make sure every access counts as a 'recently used' event.

Algorithms & Data StructuresSystem Design
Author's notes

I knew LRU cache cold going in.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and edge cases, then explain that a hash map combined with a doubly linked list achieves O(1) for all operations. Walk through the design, implement the class, and discuss test cases covering eviction, updates, and deletes.

Pro tip: Emphasize that every get and put counts as a 'recently used' event, and use a doubly linked list with sentinel nodes to simplify edge cases. Also, mention thread-safety considerations if the cache might be used concurrently.

1. Clarify Requirements and Edge Cases

Ask about capacity constraints, behavior when capacity is zero, and whether delete should remove the key entirely or just mark it as unused. Confirm that all operations must be O(1).

2. Design the Data Structures

Propose a hash map for O(1) key lookup and a doubly linked list to maintain usage order. Explain that the map stores key -> node, and the list orders nodes from most to least recently used.

3. Implement the LRU Cache Class

Write the constructor to initialize capacity, map, and sentinel head/tail nodes. Implement get, put, and delete by moving accessed nodes to the front and removing the least recently used node when capacity is exceeded.

4. Walk Through Test Cases

Describe test scenarios: basic get/put, eviction when full, updating an existing key, deleting a key, and accessing a key to refresh its recency. Mention edge cases like capacity 1 and deleting non-existent keys.

5. Analyze Complexity and Discuss Optimizations

Confirm that all operations are O(1) time and O(capacity) space. Optionally discuss thread-safety using locks or concurrent data structures if needed.

Key Points to Mention

  • Hash map provides O(1) access to nodes, and doubly linked list allows O(1) removal and insertion.
  • Sentinel nodes (dummy head and tail) simplify edge cases and avoid null checks.
  • Every get and put operation must move the accessed node to the front (most recently used).
  • Eviction removes the node just before the tail (least recently used) when capacity is exceeded.
  • Delete operation removes the key from both the map and the list in O(1).
  • Test cases should cover eviction order, updating existing keys, and deleting keys that may or may not exist.

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