← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Went through a technical phone screen for a Software Engineer role at Uber and got hit with the classic LRU cache design question. Nothing too surprising but the O(1) constraint is where people usually trip up, and I was no exception at first.

Questions Asked (1)

Q1

Design and implement an LRU cache class that supports get and put operations, both in O(1) average time, with a fixed capacity that evicts the least recently used entry when full.

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

My first instinct was to reach for a plain dict, which obviously doesn't track order.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then propose a design using a hash map and a doubly linked list to achieve O(1) operations. Walk through the implementation details, including edge cases and potential optimizations, and discuss trade-offs with alternative approaches.

Pro tip: Mention that you would use a doubly linked list with sentinel nodes to simplify edge cases, and discuss how you would handle concurrency if needed, showing awareness of real-world scenarios.

1. Clarify Requirements

Ask about expected capacity, thread-safety, and whether the cache should be in-memory or distributed. Confirm that get and put must be O(1) and that eviction is based on least recent use.

2. Choose Data Structures

Explain that a hash map provides O(1) access to nodes, and a doubly linked list maintains usage order. The combination allows O(1) updates and evictions.

3. Design Operations

Detail how get moves the accessed node to the front (most recently used), and put inserts or updates a node, moving it to the front, and evicts the tail if capacity is exceeded.

4. Handle Edge Cases

Discuss handling of capacity 0 or 1, updating existing keys, and ensuring sentinel nodes simplify boundary conditions. Mention potential concurrency issues if applicable.

5. Analyze and Optimize

Confirm O(1) time and O(capacity) space. Discuss trade-offs: e.g., using an ordered dictionary in Python, or alternative eviction policies like LFU. Mention possible optimizations like lock striping for concurrency.

Key Points to Mention

  • Hash map for O(1) key lookup, mapping keys to nodes in a doubly linked list.
  • Doubly linked list to maintain access order, with most recently used at head and least recently used at tail.
  • Sentinel nodes (dummy head and tail) to avoid null checks and simplify insertion/removal.
  • Eviction policy: when capacity is reached, remove the tail node and its corresponding hash map entry.
  • Time complexity: O(1) for both get and put; space complexity: O(capacity).
  • Potential concurrency considerations: use locks or concurrent data structures if thread-safety is required.

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